Class GorgonChunkFile<T>
Base class for a Gorgon chunked formatted data readers/writers.
Inherited Members
Namespace: Gorgon.IO
Assembly: Gorgon.Core.dll
Syntax
public abstract class GorgonChunkFile<T>
Type Parameters
Name | Description |
---|---|
T | The type of read/writer to use when deserializing or serializing the data. |
Remarks
This allows access to a file format that uses the concept of grouping sections of an object together into a grouping called a chunk. This chunk will hold binary data associated with an object allows the developer to read/write only the pieces of the object that are absolutely necessary while skipping optional chunks.
A more detailed explanation of the chunk file format can be found in the
A chunk file object will expose a collection of GorgonChunk values, and these give the available chunks in the file and can be looked up either by the ulong value for the chunk ID, or an 8 character string that represents the chunk (this is recommended for readability). This allows an application to do validation on the chunk file to ensure that its format is correct. It also allows an application to discard chunks it doesn't care about or are optional. This allows for some level of versioning between chunk file formats.
Chunks can be accessed in any order, not just the order in which they were written. This allows an application to only take the pieces they require from the file, and leave the rest. It also allows for optional chunks that can be skipped if not present, and read/written when they are.
tip
Gorgon uses the chunked file format for its own file serializing/deserializing of its objects that support persistence.
Constructors
| Edit this page View SourceGorgonChunkFile(Stream)
Initializes a new instance of the GorgonChunkFile<T> class.
Declaration
protected GorgonChunkFile(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The stream that contains the chunk file to read or write. |
Remarks
The stream
passed to this method requires that the CanSeek property returns a value of true.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
ArgumentEmptyException | Thrown when the |
See Also
Fields
| Edit this page View SourceChunkTableID
The chunk table chunk ID (CHUNKTBL)
Declaration
public const ulong ChunkTableID = 5495047177758918723
Field Value
Type | Description |
---|---|
ulong |
See Also
| Edit this page View SourceFileFormatHeaderIDv0100
The header ID for the 1.0 version of the chunk file format. (GCFF0100)
Declaration
public const ulong FileFormatHeaderIDv0100 = 3472329396109853511
Field Value
Type | Description |
---|---|
ulong |
See Also
Properties
| Edit this page View SourceChunks
Property to return the list of chunks available in the file.
Declaration
public IGorgonReadOnlyChunkCollection Chunks { get; }
Property Value
Type | Description |
---|---|
IGorgonReadOnlyChunkCollection |
Remarks
Use this property to determine if a chunk exists when reading a chunk file.
See Also
| Edit this page View SourceIsOpen
Property to return whether or not the file is open.
Declaration
public bool IsOpen { get; }
Property Value
Type | Description |
---|---|
bool |
See Also
| Edit this page View SourceStream
Property to return the GorgonStreamWrapper that contains the chunked file.
Declaration
public GorgonStreamWrapper Stream { get; }
Property Value
Type | Description |
---|---|
GorgonStreamWrapper |
See Also
Methods
| Edit this page View SourceClose()
Function to close an open chunk file in the stream.
Declaration
public void Close()
Remarks
Always call this method when a call to Open() is made. Failure to do so could cause the file to become corrupted.
If the file is not open, then this method will do nothing.
See Also
| Edit this page View SourceCloseChunk()
Function to close an open chunk.
Declaration
public abstract void CloseChunk()
Remarks
This method should always be called when one of the OpenChunk(ulong) methods are called. Failure to do so may cause file corruption.
See Also
| Edit this page View SourceOnClose()
Function called when a chunk file is closing.
Declaration
protected abstract long OnClose()
Returns
Type | Description |
---|---|
long | The total number of bytes read or written. |
See Also
| Edit this page View SourceOnOpen()
Function called when a chunk file is opening.
Declaration
protected abstract void OnOpen()
See Also
| Edit this page View SourceOpen()
Function to open a chunked file within the stream.
Declaration
public void Open()
Remarks
This opens a Gorgon chunk file that exists within the Stream passed to the constructor of this object. Typically this would be in a FileStream, but any type of stream is valid and can contain a chunk file.
If the this method is called and the file is already opened, then it will be closed and reopened.
Important
Always pair a call to Open
with a call to Close(), otherwise the file may become corrupted or the stream may not be updated to the correct position.
Important
When this file is opened for reading, then validation is performed on the file header to ensure that it is a genuine GCFF file. If it is not, then an exception will be thrown detailing what's wrong with the header.
Exceptions
Type | Condition |
---|---|
GorgonException | Thrown when the chunk file format header ID does not match when reading. -or- Thrown when application specific header ID in the file was not found in the list passed to the constructor when reading. -or- Thrown if the chunk file table offset is less than or equal to the size of the header when reading. -or- Thrown if the file size recorded in the header is less than the size of the header when reading. |
See Also
| Edit this page View SourceOpenChunk(string)
Function to open a chunk, by the text representation of its ID, for reading or writing.
Declaration
public T OpenChunk(string chunkName)
Parameters
Type | Name | Description |
---|---|---|
string | chunkName | The name of the chunk. |
Returns
Type | Description |
---|---|
T | A GorgonBinaryReader, or GorgonBinaryWriter that will allow reading or writing within the chunk. |
Remarks
See the OpenChunk(ulong), or the OpenChunk(ulong) method for more information.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
ArgumentEmptyException | Thrown when the |
See Also
| Edit this page View SourceOpenChunk(ulong)
Function to open a chunk for reading or writing.
Declaration
public abstract T OpenChunk(ulong chunkId)
Parameters
Type | Name | Description |
---|---|---|
ulong | chunkId | The ID of the chunk to open. |
Returns
Type | Description |
---|---|
T | A GorgonBinaryReader, or GorgonBinaryWriter that will allow reading or writing within the chunk. |
Remarks
See the OpenChunk(ulong), or the OpenChunk(ulong) methods for detailed information on what this method does during reading/writing contexts.
See Also
| Edit this page View SourceValidateChunkID(ulong)
Function to perform validation against the requested chunk ID and the list of reserved values.
Declaration
protected void ValidateChunkID(ulong chunkId)
Parameters
Type | Name | Description |
---|---|---|
ulong | chunkId | Chunk ID to evaluate. |
Exceptions
Type | Condition |
---|---|
ArgumentEmptyException | Thrown when the |