createByteReader
Creates a cursor over bytes, for decoding binary formats: fixed-size integers and floats,
LEB128 varints (signed ones zigzag-encoded), byte runs and NUL-terminated strings. Mirrors the
Rust bytes::ByteReader of helpers4.
A read never throws on bad data: it returns undefined and leaves the position untouched,
enough to build a precise error in the caller’s own error type.
Available since v3.1.8
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
data | Uint8Array | The bytes to decode |
Returns
Section titled “Returns”ByteReader — A ByteReader at position 0
Examples
Section titled “Examples”Decode a small binary record
Section titled “Decode a small binary record”Each read returns the value and moves on; at the end of the data it returns undefined.
A truncated read does not move the cursor
Section titled “A truncated read does not move the cursor”position tells where the failed read started, to report a precise error.
Related Types
Section titled “Related Types”ByteReader
Section titled “ByteReader”A reader created by createByteReader. Every read* method returns undefined when the
data is truncated or invalid, and then leaves the position where it was, so position is
the offset of the read that failed.
Endian
Section titled “Endian”Byte order of a multi-byte value.
