new Writer()
In addition to the named writing methods documented below,
the same methods are indexed by the NBT type number as well,
as shown in the example below.
- Source:
- See:
Example
var writer = new nbt.Writer();
// all equivalent
writer.int(42);
writer[3](42);
writer(nbt.tagTypes.int)(42);
// overwrite the second int
writer.offset = 0;
writer.int(999);
return writer.buffer;
Members
offset :number
The location in the buffer where bytes are written or read.
This increases after every write, but can be freely changed.
The buffer will be resized when necessary.
Type:
- number
Methods
byte(value) → {module:nbt.Writer}
Parameters:
Name | Type | Description |
---|---|---|
value |
number | a signed byte |
Returns:
itself
- Type
- module:nbt.Writer
byteArray(value) → {module:nbt.Writer}
Parameters:
Name | Type | Description |
---|---|---|
value |
Array.<number> | Uint8Array | Buffer |
Returns:
itself
- Type
- module:nbt.Writer
compound(value) → {module:nbt.Writer}
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value |
Object | a key/value map
Properties
|
Returns:
itself
- Type
- module:nbt.Writer
Example
writer.compound({
foo: { type: 'int', value: 12 },
bar: { type: 'string', value: 'Hello, World!' }
});
float(value) → {module:nbt.Writer}
Parameters:
Name | Type | Description |
---|---|---|
value |
number | a signed 64-bit float |
Returns:
itself
- Type
- module:nbt.Writer
float(value) → {module:nbt.Writer}
Parameters:
Name | Type | Description |
---|---|---|
value |
number | a signed 32-bit float |
Returns:
itself
- Type
- module:nbt.Writer
getData() → {ArrayBuffer}
Returns the writen data as a slice from the internal buffer,
cutting off any padding at the end.
Returns:
a [0, offset] slice of the interal buffer
- Type
- ArrayBuffer
int(value) → {module:nbt.Writer}
Parameters:
Name | Type | Description |
---|---|---|
value |
number | a signed 32-bit integer |
Returns:
itself
- Type
- module:nbt.Writer
intArray(value) → {module:nbt.Writer}
Parameters:
Name | Type | Description |
---|---|---|
value |
Array.<number> |
Returns:
itself
- Type
- module:nbt.Writer
list(value) → {module:nbt.Writer}
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
value |
Object |
Properties
|
Returns:
itself
- Type
- module:nbt.Writer
long(value) → {module:nbt.Writer}
As JavaScript does not support 64-bit integers natively, this
method takes an array of two 32-bit integers that make up the
upper and lower halves of the long.
Parameters:
Name | Type | Description |
---|---|---|
value |
Array.<number> | [upper, lower] |
Returns:
itself
- Type
- module:nbt.Writer
longArray(value) → {module:nbt.Writer}
Parameters:
Name | Type | Description |
---|---|---|
value |
Array.<number> |
Returns:
itself
- Type
- module:nbt.Writer
short(value) → {module:nbt.Writer}
Parameters:
Name | Type | Description |
---|---|---|
value |
number | a signed 16-bit integer |
Returns:
itself
- Type
- module:nbt.Writer
string(value) → {module:nbt.Writer}
Parameters:
Name | Type | Description |
---|---|---|
value |
string |
Returns:
itself
- Type
- module:nbt.Writer
ubyte(value) → {module:nbt.Writer}
Parameters:
Name | Type | Description |
---|---|---|
value |
number | an unsigned byte |
Returns:
itself
- Type
- module:nbt.Writer