Gets the underlying Buffer.
Gets the length of the buffer in bytes.
Gets the current pointer position.
Reads a specified number of bytes from the current pointer. Advances the pointer by the number of bytes read.
Optionallength:
number
The number of bytes to read. If undefined, reads to the end.
A Buffer containing the read bytes.
Reads a 64-bit signed integer (big-endian) from the current pointer. Advances the pointer by 8 bytes (or specified size).
Number of bytes to advance the pointer. Defaults to 8.
The read bigint.
Reads a 64-bit signed integer (little-endian) from the current pointer. Advances the pointer by 8 bytes (or specified size).
Number of bytes to advance the pointer. Defaults to 8.
The read bigint.
Reads a 64-bit unsigned integer (big-endian) from the current pointer. Advances the pointer by 8 bytes (or specified size).
Number of bytes to advance the pointer. Defaults to 8.
The read bigint.
Reads a 64-bit unsigned integer (little-endian) from the current pointer. Advances the pointer by 8 bytes (or specified size).
Number of bytes to advance the pointer. Defaults to 8.
The read bigint.
Reads a 64-bit floating point number (big-endian) from the current pointer. Advances the pointer by 8 bytes (or specified size).
Number of bytes to advance the pointer. Defaults to 8.
The read double.
Reads a 64-bit floating point number (little-endian) from the current pointer. Advances the pointer by 8 bytes (or specified size).
Number of bytes to advance the pointer. Defaults to 8.
The read double.
Reads a 32-bit floating point number (big-endian) from the current pointer. Advances the pointer by 4 bytes (or specified size).
Number of bytes to advance the pointer. Defaults to 4.
The read float.
Reads a 32-bit floating point number (little-endian) from the current pointer. Advances the pointer by 4 bytes (or specified size).
Number of bytes to advance the pointer. Defaults to 4.
The read float.
Reads a 32-bit signed integer (big-endian) from the current pointer. Advances the pointer by 4 bytes (or specified size).
Number of bytes to advance the pointer. Defaults to 4.
The read integer.
Reads a 32-bit signed integer (little-endian) from the current pointer. Advances the pointer by 4 bytes (or specified size).
Number of bytes to advance the pointer. Defaults to 4.
The read integer.
Reads a 32-bit unsigned integer (big-endian) from the current pointer. Advances the pointer by 4 bytes (or specified size).
Number of bytes to advance the pointer. Defaults to 4.
The read unsigned integer.
Reads a 32-bit unsigned integer (little-endian) from the current pointer. Advances the pointer by 4 bytes (or specified size).
Number of bytes to advance the pointer. Defaults to 4.
The read unsigned integer.
Returns a new BytesIO instance containing a slice of the buffer.
Arguments passed to Buffer.subarray.
A new BytesIO instance with the sliced buffer.
Returns a JSON representation of the buffer.
The buffer as a JSON object.
Returns a string representation of the buffer.
Arguments passed to Buffer.toString.
The buffer as a string.
Appends data to the end of the buffer.
The Buffer to append.
The BytesIO instance (for chaining).
Staticalloc
Allocates a new BytesIO instance with a buffer of the given size.
The size of the buffer to allocate.
A new BytesIO instance.
Staticconcat
Concatenates an array of Buffers into a new BytesIO instance.
The array of Buffers to concatenate.
A new BytesIO instance.
Staticfrom
Creates a new BytesIO instance from the given input.
The input data (Buffer, Array, string, etc.).
Optionalencode:
any
Optional encoding if input is a string.
A new BytesIO instance.
A class for reading and writing binary data using Node.js Buffers, similar to Python's BytesIO. Provides methods for seeking, slicing, reading, and writing various data types.
Remarks
This class is useful for manipulating binary data in memory, supporting random access and reading/writing of integers, floats, and raw buffers.
Example