BinaryStream is a utility to efficiently encode and decode numbers to / from a Uint8Array.
BinaryStream uses a number of internal typed arrays to avoid small array allocations when reading
and writing.
buffer() returns the stream's buffer sliced to the 8-byte rounded read or write offset
Returns Uint8Array
readArray
readArray<T>(readElement): T[]
readArray() reads a length-prefixed array of T elements from the buffer at the next 32-bit
aligned offset, using the provided callback to read the individual elements
readBool() reads a boolean from the buffer at the next byte offset
Returns boolean
readCond
readCond<T, F>(fns): T | F
readCond() reads a boolean condition from the buffer, then either calls if_true if
the condition was is true, otherwise if_false
Type Parameters
T
F
Parameters
fns: { if_false: (() => F); if_true: (() => T); }
if_false: (() => F)
(): F
Returns F
if_true: (() => T)
(): T
Returns T
Returns T | F
readF16
readF16(): number
readF16() reads a float16 from the buffer at the next 16-bit aligned offset
Returns number
readF32
readF32(): number
readF32() reads a float32 from the buffer at the next 32-bit aligned offset
Returns number
readF64
readF64(): number
readF64() reads a float64 from the buffer at the next 64-bit aligned offset
Returns number
readI16
readI16(): number
readI16() reads a int16 from the buffer at the next 16-bit aligned offset
Returns number
readI32
readI32(): number
readI32() reads a int32 from the buffer at the next 32-bit aligned offset
Returns number
readI64
readI64(): bigint
readI64() reads a bigint from the buffer at the next 64-bit aligned offset
Returns bigint
readI8
readI8(): number
readI8() reads a int8 from the buffer at the next byte offset
Returns number
readString
readString(): string
readString() writes a length-prefixed UTF-16 string from the buffer at the next 32-bit aligned
offset
Returns string
readU16
readU16(): number
readU16() reads a uint16 from the buffer at the next 16-bit aligned offset
Returns number
readU32
readU32(): number
readU32() reads a uint32 from the buffer at the next 32-bit aligned offset
Returns number
readU8
readU8(): number
readU8() reads a uint8 from the buffer at the next byte offset
Returns number
writeArray
writeArray<T>(value, writeElement): void
writeArray() writes a length-prefixed array of T elements to the buffer at the next 32-bit
aligned offset, using the provided callback to write the individual elements
BinaryStream is a utility to efficiently encode and decode numbers to / from a Uint8Array. BinaryStream uses a number of internal typed arrays to avoid small array allocations when reading and writing.