Optional buffer: BufferThe NodeJS buffer to wrap, optional
Optional options: BufWrapperOptions<Plugins>Options to apply to the buffer wrapper, optional
The wrapped NodeJS buffer
Private buffersList of buffers, used for the oneConcat option
Current offset (used for reading)
Optional optionsOptions that apply to the current BufWrapper instance
Installed plugins so you can access them from this object
Static defaultObject containing plugins that will be automatically
installed to new BufWrapper instances.
When the BufWrapperOptions#oneConcat is set to true
you must call this method to concatenate all buffers
into one. If the option is undefined or set to false,
this method will throw an error.
This method will also set the BufWrapper#buffer to the
concatenated buffer.
The concatenated buffer.
Read raw bytes from the buffer
The bytes read from the buffer
const buffer = Buffer.from([ 0x01, 0x02, 0x03 ]);
const buf = new BufWrapper(buffer);
const decoded = buf.readBytes(3);
console.log(decoded); // <Buffer 01 02 03>
The number of bytes to read
Read an array of ints from the buffer
The array read from the buffer
const buffer = Buffer.from([ 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03 ]);
const buf = new BufWrapper(buffer);
const decoded = buf.readIntArray();
console.log(decoded); // [ 1, 2, 3 ]
Read a long from the buffer
The long value read from the buffer
const buffer = Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x5b, 0xcd, 0x15]);
const buf = new BufWrapper(buffer);
const decoded = buf.readLong();
console.log(decoded); // 123456789
Read a string from the buffer (will use the ut8 encoding)
The string value read from the buffer
const buffer = Buffer.from([0x0b, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64]);
const buf = new BufWrapper(buffer);
const decoded = buf.readString();
console.log(decoded); // Hello World
Read an array of strings from the buffer
The array read from the buffer
const buffer = Buffer.from([0x02, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x05, 0x57, 0x6f, 0x72, 0x6c, 0x64]);
const buf = new BufWrapper(buffer);
const decoded = buf.readStringArray();
console.log(decoded); // ['Hello', 'World']
Read an UUID from the buffer
The UUID read from the buffer
const buffer = Buffer.from([ 0xC0, 0x9B, 0x74, 0xB4, 0x8C, 0x14, 0x44, 0xCB, 0xB5, 0x67, 0x65, 0x76, 0xA2, 0xDA, 0xF1, 0xF9 ]);
const buf = new BufWrapper(buffer);
const decoded = buf.readUUID();
console.log(decoded); // UUID <c09b74b4-8c14-44cb-b567-6576a2daf1f9>
Write an array of strings to the buffer
const buf = new BufWrapper();
buf.writeStringArray(['Hello', 'World']);
console.log(buf.buffer); // <Buffer 02 05 48 65 6c 6c 6f 05 57 6f 72 6c 64>
The value to write (string[])
Write an UUID to the buffer
import { parseUUID } from '@minecraft-js/uuid';
const uuid = parseUUID('c09b74b4-8c14-44cb-b567-6576a2daf1f9');
const buf = new BufWrapper();
buf.writeUUID(uuid);
console.log(buf.buffer); // <Buffer C0 9B 74 B4 8C 14 44 CB B5 67 65 76 A2 DA F1 F9>
The value to write (UUID instance)
Generated using TypeDoc
Create a new buffer wrapper instance