Creates a new BinaryStream instance.
Optional
buffer: Buffer<ArrayBufferLike>The array or Buffer containing binary data.
The initial pointer position.
Private
readPrivate
readPrivate
writePrivate
writePrivate
writePrivate
addIncreases the write offset by the given length.
Clears the whole BinaryStream instance.
Private
doDo read assertions, check if the read buffer is null.
Private
doDo read assertions, check if the read buffer is null.
Private
ensureEnsures write buffer has enough capacity, grows if needed.
Returns whatever or not the read offset is at end of line.
Returns the read buffer if available.
Retuns the read index.
Returns the write buffer.
Returns the write index.
Reads a slice of buffer by the given length.
Reads a boolean (true or false).
Reads an unsigned byte (0 to 255).
Returns a 64 bit (8 bytes) big-endian flating point number.
Returns a 64 bit (8 bytes) little-endian flating point number.
Returns a 32 bit (4 bytes) big-endian flating point number.
Returns a 32 bit (4 bytes) big-endian flating point number.
Reads a 32 bit (4 bytes) big-endian signed number.
Reads a 32 bit (4 bytes) signed number.
Returns a 64 bit (8 bytes) signed big-endian number.
Returns a 64 bit (8 bytes) signed little-endian number.
Reads the remaining bytes and returns the buffer slice.
Reads a 16 bit (2 bytes) signed big-endian number.
Reads a 16 bit (2 bytes) signed little-endian number.
Reads a signed byte (-128 to 127).
Reads a 24 bit (3 bytes) signed big-endian number.
Reads a 24 bit (3 bytes) little-endian number.
Reads a 32 bit (4 bytes) big-endian unsigned number.
Reads a 32 bit (4 bytes) little-endian unsigned number.
Returns a 64 bit (8 bytes) unsigned big-endian number.
Returns a 64 bit (8 bytes) unsigned little-endian number.
Reads a 16 bit (2 bytes) unsigned big-endian number.
Reads a 16 bit (2 bytes) unsigned little-endian number.
Reads a 24 bit (3 bytes) unsigned big-endian number.
Reads a 24 bit (3 bytes) unsigned little-endian number.
Reads a 32 bit unsigned number.
Reads a 64 bit unsigned variable-length number.
Reads a 32 bit (4 bytes) zigzag-encoded number.
Reads a 64 bit zigzag-encoded variable-length number.
Conventional method to reuse the stream without having to create a new BinaryStream instance.
The new buffer instance.
Sets the buffer for reading. make sure to reset the reading index!
The new Buffer.
See setReadBuffer and setWriteBuffer.
Sets the buffer for reading.
The new Buffer.
The new read index (default: 0, pass -1 to keep current).
Sets the reading index.
The new read index.
Sets the buffer for writing.
The new Buffer.
The new write index (default: 0, pass -1 to keep current).
Sets the new writing index.
The new write index.
Skips len bytes on the buffer.
Appends a buffer to the main buffer.
Writes a boolean (true or false).
Writes an unsigned byte (0 to 255).
Writes a 64 bit (8 bytes) big-endian floating point number.
Writes a 64 bit (8 bytes) little-endian floating point number.
Writes a 32 bit (4 bytes) big-endian floating point number.
Writes a 32 bit (4 bytes) little-endian floating point number.
Writes a 32 bit (4 bytes) big-endian signed number.
Writes a 32 bit (4 bytes) little-endian signed number.
Writes a 64 bit (8 bytes) signed big-endian number.
Writes a 64 bit (8 bytes) signed little-endian number.
Writes a 16 bit (2 bytes) signed big-endian number.
Writes a 16 bit (2 bytes) signed little-endian number.
Writes a signed byte (-128 to 127).
Writes a 24 bit (3 bytes) signed big-endian number.
Writes a 24 bit (3 bytes) signed little-endian number.
Writes a 32 bit (4 bytes) big-endian unsigned number.
Writes a 32 bit (4 bytes) little-endian unsigned number.
Writes a 64 bit (8 bytes) unsigned big-endian number.
Writes a 64 bit (8 bytes) unsigned little-endian number.
Writes a 16 bit (2 bytes) unsigned big-endian number.
Writes a 16 bit (2 bytes) unsigned little-endian number.
Writes a 24 bit (3 bytes) unsigned big-endian number.
Writes a 24 bit (3 bytes) unsigned little-endian number.
Writes a 32 bit unsigned number with variable-length.
Writes a 64 bit unsigned variable-length number.
Writes a 32 bit (4 bytes) zigzag-encoded number.
Writes a 64 bit unsigned zigzag-encoded number.
A high-performance binary stream for reading and writing binary data.
Unlike Node.js native buffers which have fixed size, BinaryStream uses dynamic buffers that grow automatically during write operations. This eliminates the need for manual resizing or inefficient
Buffer.concat()
calls.Example: Reading data
Example: Writing data