Skip to main content

Class: ByteStreamReader

A class that provides methods to read data from a buffer.

Extends

Accessors

buffer

Get Signature

get buffer(): ArrayBufferLike

Returns the underlying buffer

Returns

ArrayBufferLike

Inherited from

ByteStream.buffer

Defined in

byte-stream.ts:103


view

Get Signature

get view(): DataView

Returns the underlying DataView instance

Returns

DataView

Inherited from

ByteStream.view

Defined in

byte-stream.ts:110


position

Get Signature

get position(): number

Returns the current offset in the buffer in bytes.

Returns

number

Inherited from

ByteStream.position

Defined in

byte-stream.ts:117

Constructors

new ByteStreamReader()

new ByteStreamReader(buffer: ArrayBufferLike): ByteStreamReader

Creates a new buffer view.

Parameters

ParameterTypeDescription

buffer

ArrayBufferLike

The ArrayBuffer/SharedArrayBuffer to read/write data from/to

Returns

ByteStreamReader

Inherited from

ByteStream.constructor

Defined in

byte-stream.ts:44

new ByteStreamReader()

new ByteStreamReader(typedArray: TypedArray): ByteStreamReader

Creates a new buffer view.

Parameters

ParameterTypeDescription

typedArray

TypedArray

The TypedArray to read/write data from/to

Returns

ByteStreamReader

Inherited from

ByteStream.constructor

Defined in

byte-stream.ts:50

Methods

readUint8()

readUint8(): number

Reads an unsigned 8-bit integer from the buffer.

Returns

number

Read value

Throws

RangeError if the buffer is out of bounds

Defined in

byte-stream-reader.ts:14


readInt8()

readInt8(): number

Reads a signed 8-bit integer from the buffer.

Returns

number

Read value

Throws

RangeError if the buffer is out of bounds

Defined in

byte-stream-reader.ts:23


readUint16()

readUint16(littleEndian: boolean): number

Reads an unsigned 16-bit integer from the buffer.

Parameters

ParameterTypeDescription

littleEndian

boolean

Whether the integer is little-endian

Returns

number

Read value

Throws

RangeError if the buffer is out of bounds

Defined in

byte-stream-reader.ts:33


readInt16()

readInt16(littleEndian: boolean): number

Reads a signed 16-bit integer from the buffer.

Parameters

ParameterTypeDescription

littleEndian

boolean

Whether the integer is little-endian

Returns

number

Read value

Throws

RangeError if the buffer is out of bounds

Defined in

byte-stream-reader.ts:45


readUint32()

readUint32(littleEndian: boolean): number

Reads an unsigned 32-bit integer from the buffer.

Parameters

ParameterTypeDescription

littleEndian

boolean

Whether the integer is little-endian

Returns

number

Read value

Throws

RangeError if the buffer is out of bounds

Defined in

byte-stream-reader.ts:57


readInt32()

readInt32(littleEndian: boolean): number

Reads a signed 32-bit integer from the buffer.

Parameters

ParameterTypeDescription

littleEndian

boolean

Whether the integer is little-endian

Returns

number

Read value

Throws

RangeError if the buffer is out of bounds

Defined in

byte-stream-reader.ts:69


readInt64()

readInt64(littleEndian: boolean): bigint

Reads an unsigned 64-bit integer from the buffer.

Parameters

ParameterTypeDescription

littleEndian

boolean

Whether the integer is little-endian

Returns

bigint

Read value

Throws

RangeError if the buffer is out of bounds

Defined in

byte-stream-reader.ts:81


readUint64()

readUint64(littleEndian: boolean): bigint

Reads a signed 64-bit integer from the buffer.

Parameters

ParameterTypeDescription

littleEndian

boolean

Whether the integer is little-endian

Returns

bigint

Read value

Throws

RangeError if the buffer is out of bounds

Defined in

byte-stream-reader.ts:93


readFloat32()

readFloat32(littleEndian: boolean): number

Reads a 32-bit floating point number from the buffer.

Parameters

ParameterTypeDescription

littleEndian

boolean

Whether the number is little-endian

Returns

number

Read value

Throws

RangeError if the buffer is out of bounds

Defined in

byte-stream-reader.ts:105


readFloat64()

readFloat64(littleEndian: boolean): number

Reads a 64-bit floating point number from the buffer.

Parameters

ParameterTypeDescription

littleEndian

boolean

Whether the number is little-endian

Returns

number

Read value

Throws

RangeError if the buffer is out of bounds

Defined in

byte-stream-reader.ts:117


readBytes()

readBytes(byteLength: number): Uint8Array

Reads a set of bytes from the buffer.

Parameters

ParameterType

byteLength

number

Returns

Uint8Array

An Uint8Array containing the read bytes

Throws

RangeError if the buffer is out of bounds

Defined in

byte-stream-reader.ts:128


readBytesUnsafe()

readBytesUnsafe(byteLength: number): Uint8Array

Reads a set of bytes from the buffer without copying.

Parameters

ParameterType

byteLength

number

Returns

Uint8Array

An Uint8Array containing the read bytes

Throws

RangeError if the buffer is out of bounds

Remarks

The returned Uint8Array shares the same memory as the buffer. Use with caution, as modifying the Uint8Array will also modify the buffer.

Defined in

byte-stream-reader.ts:145


readSchema()

readSchema<T>(schema: T): InferSchemaType<T>

Reads a schema from the buffer.

Type Parameters

Type Parameter

T extends SchemaLike<unknown, ByteStream, ByteStream>

Parameters

ParameterTypeDescription

schema

T

The schema to read

Returns

InferSchemaType<T>

The value read from the buffer

Throws

RangeError if the buffer is out of bounds

Defined in

byte-stream-reader.ts:157


subarray()

subarray(start: number, end: number): Uint8Array

Returns a subarray of the buffer.

Parameters

ParameterTypeDescription

start

number

The start offset in bytes

end

number

The end offset in bytes

Returns

Uint8Array

The subarray

Remarks

The returned Uint8Array shares the same memory as the buffer.

Inherited from

ByteStream.subarray

Defined in

byte-stream.ts:74


seek()

seek(position: number): void

Seeks to a specific offset in the buffer.

Parameters

ParameterTypeDescription

position

number

The offset to seek to

Returns

void

Throws

RangeError if the position is out of bounds

Inherited from

ByteStream.seek

Defined in

byte-stream.ts:83


skip()

skip(offset: number): void

Skips a number of bytes in the buffer.

Parameters

ParameterTypeDescription

offset

number

The number of bytes to skip

Returns

void

Throws

RangeError if the offset is out of bounds

Inherited from

ByteStream.skip

Defined in

byte-stream.ts:96

Properties

PropertyModifierTypeDescriptionInherited fromDefined in
_bufferprotectedArrayBufferLikeThe underlying buffer.ByteStream._bufferbyte-stream.ts:23
_viewprotectedDataViewThe DataView instance to read data from the buffer.ByteStream._viewbyte-stream.ts:28
_u8protectedUint8ArrayThe Uint8Array instance to read data from the buffer.ByteStream._u8byte-stream.ts:33
_offsetprotectednumberThe current offset in the buffer in bytes.ByteStream._offsetbyte-stream.ts:38