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:109


view​

Get Signature​

get view(): DataView

Returns the underlying DataView instance

Returns​

DataView

Inherited from​

ByteStream.view

Defined in​

byte-stream.ts:116


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:123

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:50

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:56

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:20


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:29


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:39


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:51


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:63


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:75


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:87


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:99


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:111


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:123


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:134


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:151


readArrayBuffer()​

readArrayBuffer(byteLength: number): ArrayBuffer

Reads an ArrayBuffer from the buffer.

Parameters​

ParameterType

byteLength

number

Returns​

ArrayBuffer

The read ArrayBuffer

Throws​

RangeError if the buffer is out of bounds

Defined in​

byte-stream-reader.ts:162


readTypedArray()​

readTypedArray<T>(TypedArray: TypedArrayConstructor<T>, elements: number): T

Reads a TypedArray from the buffer.

Type Parameters​

Type Parameter

T extends TypedArray

Parameters​

ParameterTypeDescription

TypedArray

TypedArrayConstructor<T>

The TypedArray constructor to use

elements

number

The number of elements to read

Returns​

T

The read TypedArray

Throws​

RangeError if the buffer is out of bounds

Defined in​

byte-stream-reader.ts:173


readString()​

readString(byteLength: number): string

Reads a string from the buffer.

Parameters​

ParameterTypeDescription

byteLength

number

The number of bytes to read

Returns​

string

The read string

Throws​

RangeError if the buffer is out of bounds

Defined in​

byte-stream-reader.ts:183


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:203


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:80


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:89


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:102

Properties​

PropertyModifierTypeDescriptionInherited fromDefined in
_bufferprotectedArrayBufferLikeThe underlying buffer.ByteStream._bufferbyte-stream.ts:29
_viewprotectedDataViewThe DataView instance to read data from the buffer.ByteStream._viewbyte-stream.ts:34
_u8protectedUint8ArrayThe Uint8Array instance to read data from the buffer.ByteStream._u8byte-stream.ts:39
_offsetprotectednumberThe current offset in the buffer in bytes.ByteStream._offsetbyte-stream.ts:44