Archive

References
public class Archive : ICloneable
This class represents a complete file. Grasshopper2 files are essentially zip-archives containing a mixture of textual, binary and node-based entries.

Constructors

Archive

#
Create a new, empty archive.
public Archive(
location
Initial location, may be null. Note that if a location is not set at time of serialisation, relative file paths cannot be constructed.
)

Fields

FileExtension

#
Gets the file extension used for Grasshopper 2.0 files (minus the period). The extension is "ghz" which stands for GrassHopperZip(ped).
public const string FileExtension = "ghz"

PathSeparator

#
Gets the folder separator character used in Archive paths. You can use forward slahes, backslashes or vertical bars in your own notation though.
public const char PathSeparator = '/'

Properties

Compression

#
Gets or sets the compression level to use when writing this archive to a file.
public Compression Compression { get; set; }

Count

#
Gets the number of distinct entries in this archive.
public int Count { get; }

Errors

#
Enumerate over all error messages.
public IEnumerable<string> Errors { get; }

HasErrors

#
Gets whether any error messages have been logged.
public bool HasErrors { get; }

HasNotes

#
Gets whether any informational messages have been logged.
public bool HasNotes { get; }

HasWarnings

#
Gets whether any warning messages have been logged.
public bool HasWarnings { get; }

Location

#
Gets the location associated with this archive. This will only be set when the archive is read or written from/to file.
public string Location { get; }

MessageCount

#
Gets the number of messages.
public int MessageCount { get; }

Notes

#
Enumerate over all informational messages.
public IEnumerable<string> Notes { get; }

Paths

#
Enumerate over all entry paths in this archive.
public IEnumerable<string> Paths { get; }

Warnings

#
Enumerate over all warning messages.
public IEnumerable<string> Warnings { get; }

Indexers

this[]

#
Get the entry at the given path.
public byte[] this[
path
Path.
] { get; }
Entry at path.

Methods

AddData

#
Add byte-array content to this archive.
public void AddData(
path,
Path for content. The path must end in either ".dat", ".png", ".jpg", ".tiff", ".zip", ".3dm", ".pdf" or ".dll"
byte[]
data
Data.
)

AddDataUnsafe

#
Add byte-array content to this archive without copying. Only use this method if you know there is no chance of the byte array being shared.
[EditorBrowsable(EditorBrowsableState.Advanced)] public void AddDataUnsafe(
path,
Path for content.
byte[]
data
Data. Array will not be cloned and as such may be shared.
)

AddRoot

#
Add a root node to this archive.
public void AddRoot(
path,
Path for content. The path must end in either ".root" or ".data"
root
Root node.
)

AddText

#
Add text content to this archive.
public void AddText(
path,
Path for content. The path must end in either ".txt", ".csv", ".cs", ".vb", ".py", ".xml", ".yaml", or ".json"
text
Text data.
)

ClearMessages

#
Wipe all messages.
public void ClearMessages()

Clone

#
Create a deep copy of this archive in memory.
public Archive Clone()

EnumerateAndExecute

#
Enumerate over all elements in this archive and invoke a delegate for each.
public void EnumerateAndExecute(
textMethod = null,
Method for handling text data.
dataMethod = null,
Method for handling byte array data.
rootMethod = null,
Method for handling root nodes.
nodeMethod = null,
Method for handling all nodes (including root nodes).
itemMethod = null
Method for handling item data.
)

GetData

#
Get the byte-array associated with the given path.
public byte[] GetData(
path
Path.
)
Byte array.

GetDataUnsafe

#
Get the byte-array associated with the given path. This method provides direct access to the internal array without duplication, so only use it if you're not going to modify this array.
[EditorBrowsable(EditorBrowsableState.Advanced)] public byte[] GetDataUnsafe(
path
Path.
)
Bytes or null if no such byte path exists.

GetRoot

#
Get the root node associated with the given path.
public Node GetRoot(
path
Path.
)
Node at path.

GetText

#
Try to get the text associated with the given path.
public string GetText(
path
Path.
)
Text or null if no such text path exists.

Read

#
Read a file and store its contents in a new archive.
public static Archive Read(
filePath,
File to parse.
filter
Entry name filter.
)
Read archive.

Read

#
Read a file and store its contents in a new archive.
public static Archive Read(
filePath
File to parse.
)
Read archive.

RecordError

#
Add an error message to this archive.
public void RecordError(
message
Message to add.
)

RecordNote

#
Add an informational message to this archive.
public void RecordNote(
message
Message to add.
)

RecordWarning

#
Add a warning message to this archive.
public void RecordWarning(
message
Message to add.
)

Remove

#
Remove an entry from this archive.
public bool Remove(
path
)
Explicit

ICloneable.Clone

#
Creates a new object that is a copy of the current instance.
A new object that is a copy of this instance.

Write

#
An overload that writes this archive to a file on the disk, and reports the number of written bytes.
public void Write(
filePath,
Path of target file.
out int
nBytesWritten
The number of written bytes.
)

Write

#
Write this archive to a file on the disk.
public void Write(
filePath
Path of target file.
)