Class NbtWriter
- Namespace
- fNbt
- Assembly
- fNbt.dll
An efficient writer for writing NBT data directly to streams. Each instance of NbtWriter writes one complete file. NbtWriter enforces all constraints of the NBT file format EXCEPT checking for duplicate tag names within a compound.
public sealed class NbtWriter
- Inheritance
-
NbtWriter
- Inherited Members
Constructors
NbtWriter(Stream, string)
Initializes a new instance of the NbtWriter class.
public NbtWriter(Stream stream, string rootTagName)
Parameters
streamStreamStream to write to.
rootTagNamestringName to give to the root tag (written immediately).
Remarks
Assumes that data in the stream should be Big-Endian encoded.
Exceptions
- ArgumentNullException
streamorrootTagNameisnull.- ArgumentException
streamis not writable.
NbtWriter(Stream, string, bool)
Initializes a new instance of the NbtWriter class.
public NbtWriter(Stream stream, string rootTagName, bool bigEndian)
Parameters
streamStreamStream to write to.
rootTagNamestringName to give to the root tag (written immediately).
bigEndianboolWhether NBT data should be in Big-Endian encoding.
Exceptions
- ArgumentNullException
streamorrootTagNameisnull.- ArgumentException
streamis not writable.
Properties
BaseStream
Gets the underlying stream of the NbtWriter.
public Stream BaseStream { get; }
Property Value
IsDone
Gets whether the root tag has been closed. No more tags may be written after the root tag has been closed.
public bool IsDone { get; }
Property Value
Methods
BeginCompound()
Begins an unnamed compound tag.
public void BeginCompound()
Exceptions
- NbtFormatException
No more tags can be written -OR- a named compound tag was expected -OR- a tag of a different type was expected -OR- the size of a parent list has been exceeded.
BeginCompound(string)
Begins a named compound tag.
public void BeginCompound(string tagName)
Parameters
tagNamestringName to give to this compound tag. May not be null.
Exceptions
- NbtFormatException
No more tags can be written -OR- an unnamed compound tag was expected -OR- a tag of a different type was expected.
BeginList(string, NbtTagType, int)
Begins an unnamed list tag.
public void BeginList(string tagName, NbtTagType elementType, int size)
Parameters
tagNamestringName to give to this compound tag. May not be null.
elementTypeNbtTagTypeType of elements of this list.
sizeintNumber of elements in this list. Must not be negative.
Exceptions
- NbtFormatException
No more tags can be written -OR- an unnamed list tag was expected -OR- a tag of a different type was expected.
- ArgumentOutOfRangeException
sizeis negative -OR-elementTypeis not a valid NbtTagType.
BeginList(NbtTagType, int)
Begins an unnamed list tag.
public void BeginList(NbtTagType elementType, int size)
Parameters
elementTypeNbtTagTypeType of elements of this list.
sizeintNumber of elements in this list. Must not be negative.
Exceptions
- NbtFormatException
No more tags can be written -OR- a named list tag was expected -OR- a tag of a different type was expected -OR- the size of a parent list has been exceeded.
- ArgumentOutOfRangeException
sizeis negative -OR-elementTypeis not a valid NbtTagType.
EndCompound()
Ends a compound tag.
public void EndCompound()
Exceptions
- NbtFormatException
Not currently in a compound.
EndList()
Ends a list tag.
public void EndList()
Exceptions
- NbtFormatException
Not currently in a list -OR- not all list elements have been written yet.
Finish()
Ensures that file has been written in its entirety, with no tags left open. This method is for verification only, and does not actually write any data. Calling this method is optional (but probably a good idea, to catch any usage errors).
public void Finish()
Exceptions
- NbtFormatException
Not all tags have been closed yet.
WriteByte(byte)
Writes an unnamed byte tag.
public void WriteByte(byte value)
Parameters
valuebyteThe unsigned byte to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- a named byte tag was expected -OR- a tag of a different type was expected -OR- the size of a parent list has been exceeded.
WriteByte(string, byte)
Writes an unnamed byte tag.
public void WriteByte(string tagName, byte value)
Parameters
tagNamestringName to give to this compound tag. May not be null.
valuebyteThe unsigned byte to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- an unnamed byte tag was expected -OR- a tag of a different type was expected.
WriteByteArray(byte[])
Writes an unnamed byte array tag, copying data from an array.
public void WriteByteArray(byte[] data)
Parameters
databyte[]A byte array containing the data to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- a named byte array tag was expected -OR- a tag of a different type was expected -OR- the size of a parent list has been exceeded.
- ArgumentNullException
datais null
WriteByteArray(byte[], int, int)
Writes an unnamed byte array tag, copying data from an array.
public void WriteByteArray(byte[] data, int offset, int count)
Parameters
databyte[]A byte array containing the data to write.
offsetintThe starting point in
dataat which to begin writing. Must not be negative.countintThe number of bytes to write. Must not be negative.
Exceptions
- NbtFormatException
No more tags can be written -OR- a named byte array tag was expected -OR- a tag of a different type was expected -OR- the size of a parent list has been exceeded.
- ArgumentOutOfRangeException
offsetorcountis negative.- ArgumentNullException
datais null- ArgumentException
countis greater thanoffsetsubtracted from the array length.
WriteByteArray(Stream, int)
Writes an unnamed byte array tag, copying data from a stream.
public void WriteByteArray(Stream dataSource, int count)
Parameters
dataSourceStreamA Stream from which data will be copied.
countintThe number of bytes to write. Must not be negative.
Remarks
A temporary buffer will be allocated, of size up to 8192 bytes. To manually specify a buffer, use one of the other WriteByteArray() overloads.
Exceptions
- NbtFormatException
No more tags can be written -OR- a named byte array tag was expected -OR- a tag of a different type was expected -OR- the size of a parent list has been exceeded.
- ArgumentOutOfRangeException
countis negative.- ArgumentNullException
dataSourceis null.- ArgumentException
Given stream does not support reading.
WriteByteArray(Stream, int, byte[])
Writes an unnamed byte array tag, copying data from a stream.
public void WriteByteArray(Stream dataSource, int count, byte[] buffer)
Parameters
dataSourceStreamA Stream from which data will be copied.
countintThe number of bytes to write. Must not be negative.
bufferbyte[]Buffer to use for copying. Size must be greater than 0. Must not be null.
Exceptions
- NbtFormatException
No more tags can be written -OR- a named byte array tag was expected -OR- a tag of a different type was expected -OR- the size of a parent list has been exceeded.
- ArgumentOutOfRangeException
countis negative.- ArgumentNullException
dataSourceis null.- ArgumentException
Given stream does not support reading -OR-
buffersize is 0.
WriteByteArray(string, byte[])
Writes a named byte array tag, copying data from an array.
public void WriteByteArray(string tagName, byte[] data)
Parameters
tagNamestringName to give to this byte array tag. May not be null.
databyte[]A byte array containing the data to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- an unnamed byte array tag was expected -OR- a tag of a different type was expected.
- ArgumentNullException
tagNameordatais null
WriteByteArray(string, byte[], int, int)
Writes a named byte array tag, copying data from an array.
public void WriteByteArray(string tagName, byte[] data, int offset, int count)
Parameters
tagNamestringName to give to this byte array tag. May not be null.
databyte[]A byte array containing the data to write.
offsetintThe starting point in
dataat which to begin writing. Must not be negative.countintThe number of bytes to write. Must not be negative.
Exceptions
- NbtFormatException
No more tags can be written -OR- an unnamed byte array tag was expected -OR- a tag of a different type was expected.
- ArgumentOutOfRangeException
offsetorcountis negative.- ArgumentNullException
tagNameordatais null- ArgumentException
countis greater thanoffsetsubtracted from the array length.
WriteByteArray(string, Stream, int)
Writes a named byte array tag, copying data from a stream.
public void WriteByteArray(string tagName, Stream dataSource, int count)
Parameters
tagNamestringName to give to this byte array tag. May not be null.
dataSourceStreamA Stream from which data will be copied.
countintThe number of bytes to write. Must not be negative.
Remarks
A temporary buffer will be allocated, of size up to 8192 bytes. To manually specify a buffer, use one of the other WriteByteArray() overloads.
Exceptions
- NbtFormatException
No more tags can be written -OR- an unnamed byte array tag was expected -OR- a tag of a different type was expected.
- ArgumentOutOfRangeException
countis negative.- ArgumentNullException
dataSourceis null.- ArgumentException
Given stream does not support reading.
WriteByteArray(string, Stream, int, byte[])
Writes an unnamed byte array tag, copying data from another stream.
public void WriteByteArray(string tagName, Stream dataSource, int count, byte[] buffer)
Parameters
tagNamestringName to give to this byte array tag. May not be null.
dataSourceStreamA Stream from which data will be copied.
countintThe number of bytes to write. Must not be negative.
bufferbyte[]Buffer to use for copying. Size must be greater than 0. Must not be null.
Exceptions
- NbtFormatException
No more tags can be written -OR- an unnamed byte array tag was expected -OR- a tag of a different type was expected.
- ArgumentOutOfRangeException
countis negative.- ArgumentNullException
dataSourceis null.- ArgumentException
Given stream does not support reading -OR-
buffersize is 0.
WriteDouble(double)
Writes an unnamed double tag.
public void WriteDouble(double value)
Parameters
valuedoubleThe eight-byte floating-point value to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- a named double tag was expected -OR- a tag of a different type was expected -OR- the size of a parent list has been exceeded.
WriteDouble(string, double)
Writes an unnamed byte tag.
public void WriteDouble(string tagName, double value)
Parameters
tagNamestringName to give to this compound tag. May not be null.
valuedoubleThe unsigned byte to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- an unnamed byte tag was expected -OR- a tag of a different type was expected.
WriteFloat(float)
Writes an unnamed float tag.
public void WriteFloat(float value)
Parameters
valuefloatThe four-byte floating-point value to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- a named float tag was expected -OR- a tag of a different type was expected -OR- the size of a parent list has been exceeded.
WriteFloat(string, float)
Writes an unnamed float tag.
public void WriteFloat(string tagName, float value)
Parameters
tagNamestringName to give to this compound tag. May not be null.
valuefloatThe four-byte floating-point value to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- an unnamed float tag was expected -OR- a tag of a different type was expected.
WriteInt(int)
Writes an unnamed int tag.
public void WriteInt(int value)
Parameters
valueintThe four-byte signed integer to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- a named int tag was expected -OR- a tag of a different type was expected -OR- the size of a parent list has been exceeded.
WriteInt(string, int)
Writes an unnamed int tag.
public void WriteInt(string tagName, int value)
Parameters
tagNamestringName to give to this compound tag. May not be null.
valueintThe four-byte signed integer to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- an unnamed int tag was expected -OR- a tag of a different type was expected.
WriteIntArray(int[])
Writes an unnamed int array tag, copying data from an array.
public void WriteIntArray(int[] data)
Parameters
dataint[]An int array containing the data to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- a named int array tag was expected -OR- a tag of a different type was expected -OR- the size of a parent list has been exceeded.
- ArgumentNullException
datais null
WriteIntArray(int[], int, int)
Writes an unnamed int array tag, copying data from an array.
public void WriteIntArray(int[] data, int offset, int count)
Parameters
dataint[]An int array containing the data to write.
offsetintThe starting point in
dataat which to begin writing. Must not be negative.countintThe number of elements to write. Must not be negative.
Exceptions
- NbtFormatException
No more tags can be written -OR- a named int array tag was expected -OR- a tag of a different type was expected -OR- the size of a parent list has been exceeded.
- ArgumentOutOfRangeException
offsetorcountis negative.- ArgumentNullException
datais null- ArgumentException
countis greater thanoffsetsubtracted from the array length.
WriteIntArray(string, int[])
Writes a named int array tag, copying data from an array.
public void WriteIntArray(string tagName, int[] data)
Parameters
tagNamestringName to give to this int array tag. May not be null.
dataint[]An int array containing the data to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- an unnamed int array tag was expected -OR- a tag of a different type was expected.
- ArgumentNullException
tagNameordatais null
WriteIntArray(string, int[], int, int)
Writes a named int array tag, copying data from an array.
public void WriteIntArray(string tagName, int[] data, int offset, int count)
Parameters
tagNamestringName to give to this int array tag. May not be null.
dataint[]An int array containing the data to write.
offsetintThe starting point in
dataat which to begin writing. Must not be negative.countintThe number of elements to write. Must not be negative.
Exceptions
- NbtFormatException
No more tags can be written -OR- an unnamed int array tag was expected -OR- a tag of a different type was expected.
- ArgumentOutOfRangeException
offsetorcountis negative.- ArgumentNullException
tagNameordatais null- ArgumentException
countis greater thanoffsetsubtracted from the array length.
WriteLong(long)
Writes an unnamed long tag.
public void WriteLong(long value)
Parameters
valuelongThe eight-byte signed integer to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- a named long tag was expected -OR- a tag of a different type was expected -OR- the size of a parent list has been exceeded.
WriteLong(string, long)
Writes an unnamed long tag.
public void WriteLong(string tagName, long value)
Parameters
tagNamestringName to give to this compound tag. May not be null.
valuelongThe eight-byte signed integer to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- an unnamed long tag was expected -OR- a tag of a different type was expected.
WriteLongArray(long[])
Writes an unnamed long array tag, copying data from an array.
public void WriteLongArray(long[] data)
Parameters
datalong[]A long array containing the data to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- a named long array tag was expected -OR- a tag of a different type was expected -OR- the size of a parent list has been exceeded.
- ArgumentNullException
datais null
WriteLongArray(long[], int, int)
Writes an unnamed long array tag, copying data from an array.
public void WriteLongArray(long[] data, int offset, int count)
Parameters
datalong[]A long array containing the data to write.
offsetintThe starting point in
dataat which to begin writing. Must not be negative.countintThe number of elements to write. Must not be negative.
Exceptions
- NbtFormatException
No more tags can be written -OR- a named long array tag was expected -OR- a tag of a different type was expected -OR- the size of a parent list has been exceeded.
- ArgumentOutOfRangeException
offsetorcountis negative.- ArgumentNullException
datais null- ArgumentException
countis greater thanoffsetsubtracted from the array length.
WriteLongArray(string, long[])
Writes a named long array tag, copying data from an array.
public void WriteLongArray(string tagName, long[] data)
Parameters
tagNamestringName to give to this long array tag. May not be null.
datalong[]A long array containing the data to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- an unnamed long array tag was expected -OR- a tag of a different type was expected.
- ArgumentNullException
tagNameordatais null
WriteLongArray(string, long[], int, int)
Writes a named long array tag, copying data from an array.
public void WriteLongArray(string tagName, long[] data, int offset, int count)
Parameters
tagNamestringName to give to this long array tag. May not be null.
datalong[]A long array containing the data to write.
offsetintThe starting point in
dataat which to begin writing. Must not be negative.countintThe number of elements to write. Must not be negative.
Exceptions
- NbtFormatException
No more tags can be written -OR- an unnamed long array tag was expected -OR- a tag of a different type was expected.
- ArgumentOutOfRangeException
offsetorcountis negative.- ArgumentNullException
tagNameordatais null- ArgumentException
countis greater thanoffsetsubtracted from the array length.
WriteShort(short)
Writes an unnamed short tag.
public void WriteShort(short value)
Parameters
valueshortThe two-byte signed integer to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- a named short tag was expected -OR- a tag of a different type was expected -OR- the size of a parent list has been exceeded.
WriteShort(string, short)
Writes an unnamed short tag.
public void WriteShort(string tagName, short value)
Parameters
tagNamestringName to give to this compound tag. May not be null.
valueshortThe two-byte signed integer to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- an unnamed short tag was expected -OR- a tag of a different type was expected.
WriteString(string)
Writes an unnamed string tag.
public void WriteString(string value)
Parameters
valuestringThe string to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- a named string tag was expected -OR- a tag of a different type was expected -OR- the size of a parent list has been exceeded.
WriteString(string, string)
Writes an unnamed string tag.
public void WriteString(string tagName, string value)
Parameters
tagNamestringName to give to this compound tag. May not be null.
valuestringThe string to write.
Exceptions
- NbtFormatException
No more tags can be written -OR- an unnamed string tag was expected -OR- a tag of a different type was expected.
WriteTag(NbtTag)
Writes a NbtTag object, and all of its child tags, to stream. Use this method sparingly with NbtWriter -- constructing NbtTag objects defeats the purpose of this class. If you already have lots of NbtTag objects, you might as well use NbtFile to write them all at once.
public void WriteTag(NbtTag tag)
Parameters
tagNbtTagTag to write. Must not be null.
Exceptions
- NbtFormatException
No more tags can be written -OR- given tag is unacceptable at this time.
- ArgumentNullException
tagis null