Skip to main content

Class: BufferReader

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

Extends

Accessors

buffer

Get Signature

get buffer(): ArrayBuffer

Returns the underlying buffer

Returns

ArrayBuffer

Inherited from

BufferView.buffer

Defined in

buffer-view.ts:75


view

Get Signature

get view(): DataView

Returns the underlying DataView instance

Returns

DataView

Inherited from

BufferView.view

Defined in

buffer-view.ts:82


position

Get Signature

get position(): number

Returns the current offset in the buffer in bytes.

Returns

number

Inherited from

BufferView.position

Defined in

buffer-view.ts:89

Constructors

new BufferReader()

new BufferReader(buffer: ArrayBuffer): BufferReader

Creates a new buffer view.

Parameters

ParameterTypeDescription

buffer

ArrayBuffer

The buffer to read/write data from/to

Returns

BufferReader

Inherited from

BufferView.constructor

Defined in

buffer-view.ts:30

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

buffer-reader.ts:13


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

buffer-reader.ts:22


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

buffer-reader.ts:32


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

buffer-reader.ts:44


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

buffer-reader.ts:56


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

buffer-reader.ts:68


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

buffer-reader.ts:80


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

buffer-reader.ts:92


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

buffer-reader.ts:104


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

buffer-reader.ts:116


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

buffer-reader.ts:127


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

buffer-reader.ts:144


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

BufferView.subarray

Defined in

buffer-view.ts:46


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

BufferView.seek

Defined in

buffer-view.ts:55


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

BufferView.skip

Defined in

buffer-view.ts:68

Properties

PropertyModifierTypeDescriptionInherited fromDefined in
_bufferprotectedArrayBufferThe underlying buffer.BufferView._bufferbuffer-view.ts:9
_viewprotectedDataViewThe DataView instance to read data from the buffer.BufferView._viewbuffer-view.ts:14
_u8protectedUint8ArrayThe Uint8Array instance to read data from the buffer.BufferView._u8buffer-view.ts:19
_offsetprotectednumberThe current offset in the buffer in bytes.BufferView._offsetbuffer-view.ts:24