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

#
public Archive(string location)
Create a new, empty archive.
location (string)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

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

PathSeparator

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

Properties

Compression

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

Count

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

Errors

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

HasErrors

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

HasNotes

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

HasWarnings

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

Location

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

MessageCount

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

Notes

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

Paths

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

Warnings

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

Indexers

this[]

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

Methods

AddData

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

AddDataUnsafe

#
[EditorBrowsable(EditorBrowsableState.Advanced)] public void AddDataUnsafe(string path, byte[] data)
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.
path (string)Path for content.
data (byte[])Data. Array will not be cloned and as such may be shared.

AddRoot

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

AddText

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

ClearMessages

#
public void ClearMessages()
Wipe all messages.

Clone

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

EnumerateAndExecute

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

GetData

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

GetDataUnsafe

#
[EditorBrowsable(EditorBrowsableState.Advanced)] public byte[] GetDataUnsafe(string path)
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.
path (string)Path.
Bytes or null if no such byte path exists.

GetRoot

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

GetText

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

Read

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

Read

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

RecordError

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

RecordNote

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

RecordWarning

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

Remove

#
public bool Remove(string path)
Remove an entry from this archive.
path (string)
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

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

Write

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