Creates a new BinaryDecoder that can read the given buffer.
Buffer to decode.
Initial offset to use (0 by default).
Endianness to use (little endian by default).
Buffer being read/written.
Total byte length of buffer.
Number of bytes between current offset and end of buffer.
Endianness currently being used to read/write data.
Whether current offset is out of the buffer's bounds.
Offset where data is currently being read/written.
Reads a single byte as a UInt8 (alias of uint8).
A single byte value.
If buffer does not contain at least 1 more byte.
Reads the given number of bytes as a string with the given encoding.
Number of bytes to read.
Character encoding to parse with ("utf-8" by default).
String parsed with given encoding.
If buffer does not contain the specified number of bytes.
Reads the given number of bytes as a string of Base64 characters.
Number of bytes to read.
The characters read as a string with Base64 encoding.
Use chars instead (use "base64" as second argument).
If buffer does not contain the specified number of bytes.
Returns a new BinaryDecoder using this coder's buffer.
Initial offset to use (0 by default).
Endianness to use (little endian by default).
New decoder for this coder's buffer.
Returns a new BinaryEncoder using this coder's buffer.
Initial offset to use (0 by default).
Endianness to use (little endian by default).
New encoder for this coder's buffer.
Returns whether this coder can safely consume the given number of bytes from the given offset (or the current offset if omitted).
Number of bytes to check.
Optional
fromOffset: numberOffset to check from, if different than current one.
True if these bytes can be safely consumed, false otherwise.
Returns whether or not the offset is at the end of the file (i.e. reading anything will cause an exception).
True if offset is at EOF, false otherwise.
Use isOutOfBounds getter instead.
Preserves the original offset after calling the given function.
Use saveOffset method instead.
Moves the offset to a specific byte.
The value to set the offset to.
Moves the offset to a specific byte.
The value to set the offset to.
Passing bigints is no longer supported.
Sets the endianness to use for reading/writing.
Endianness to use.
Advances the offset by the given number of bytes.
The number of bytes to skip.
The new offset after skipping bytes.
Advances the offset by the given number of bytes.
The number of bytes to skip.
The new offset after skipping bytes.
Passing bigints is no longer supported.
Reads bytes until a null byte is found, parses them as a string with UTF-8 encoding, and returns the result. The offset will be advanced by the byte length + 1 (for the null byte).
The string read with UTF-8 encoding.
Use terminatedString instead.
If there is no null byte between current offset and end of buffer.
Returns the current offset.
The current offset.
Use offset getter instead.
Reads bytes until a null byte is found, parses them as a string with the given encoding, and returns the result. The offset will be advanced by the byte length + 1 (for the null byte).
Character encoding to parse with ("utf-8" by default).
String parsed with given encoding.
If there is no null byte between current offset and end of buffer.
Reads a 16-bit unsigned integer. Consumes 2 bytes.
The read UInt16.
If buffer does not contain at least 2 more bytes.
Reads a 16-bit unsigned integer, applies the given bit masks, and returns the masked values in an array. Consumes 2 bytes.
// flag is the first bit, value is the remaining 15
const [flag, value] = decoder.uint16({ bits: [1, 15] });
Bit masks to apply to decoded value.
Array of values after applying bit masks to the read UInt16.
If buffer does not contain at least 2 more bytes, or if bit masks are not valid.
Reads a 32-bit unsigned integer. Consumes 4 bytes.
The read UInt32.
If buffer does not contain at least 4 more bytes.
Reads a 32-bit unsigned integer, applies the given bit masks, and returns the masked values in an array. Consumes 4 bytes.
// flag is the first bit, value is the remaining 31
const [flag, value] = decoder.uint32({ bits: [1, 31] });
Bit masks to apply to decoded value.
Array of values after applying bit masks to the read UInt32.
If buffer does not contain at least 4 more bytes, or if bit masks are not valid.
Reads a 64-bit unsigned integer. Consumes 8 bytes.
The read UInt64.
If buffer does not contain at least 8 more bytes.
Reads a 64-bit unsigned integer, applies the given bit masks, and returns the masked values in an array. Consumes 8 bytes.
// flag is the first bit, value is the remaining 63
const [flag, value] = decoder.uint64({ bits: [1, 63] });
Bit masks to apply to decoded value.
Array of values after applying bit masks to the read UInt64.
If buffer does not contain at least 8 more bytes, or if bit masks are not valid.
Reads an 8-bit unsigned integer. Consumes 1 byte.
The read UInt8.
If buffer does not contain at least 1 more byte.
Reads an 8-bit unsigned integer, applies the given bit masks, and returns the masked values in an array. Consumes 1 byte.
// flag is the first bit, value is the remaining 7
const [flag, value] = decoder.uint8({ bits: [1, 7] });
Bit masks to apply to decoded value.
Array of values after applying bit masks to the read UInt8.
If buffer does not contain at least 1 more byte, or if bit masks are not valid.
Temporarily sets the endianness to the given value, calls the given function, and then restores the original endianness.
Endianness to use in scope of function.
Function to call.
Result of the given function call.
Decodes binary data from a buffer.