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
Defined in
view
Get Signature
get view():
DataView
Returns the underlying DataView instance
Returns
Inherited from
Defined in
position
Get Signature
get position():
number
Returns the current offset in the buffer in bytes.
Returns
number
Inherited from
Defined in
Constructors
new ByteStreamReader()
new ByteStreamReader(
buffer:ArrayBufferLike):ByteStreamReader
Creates a new buffer view.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| The ArrayBuffer/SharedArrayBuffer to read/write data from/to |
Returns
Inherited from
Defined in
new ByteStreamReader()
new ByteStreamReader(
typedArray:TypedArray):ByteStreamReader
Creates a new buffer view.
Parameters
| Parameter | Type | Description |
|---|---|---|
| The TypedArray to read/write data from/to |
Returns
Inherited from
Defined in
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
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
readUint16()
readUint16(
littleEndian:boolean):number
Reads an unsigned 16-bit integer from the buffer.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| Whether the integer is little-endian |
Returns
number
Read value
Throws
RangeError if the buffer is out of bounds
Defined in
readInt16()
readInt16(
littleEndian:boolean):number
Reads a signed 16-bit integer from the buffer.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| Whether the integer is little-endian |
Returns
number
Read value
Throws
RangeError if the buffer is out of bounds
Defined in
readUint32()
readUint32(
littleEndian:boolean):number
Reads an unsigned 32-bit integer from the buffer.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| Whether the integer is little-endian |
Returns
number
Read value
Throws
RangeError if the buffer is out of bounds
Defined in
readInt32()
readInt32(
littleEndian:boolean):number
Reads a signed 32-bit integer from the buffer.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| Whether the integer is little-endian |
Returns
number
Read value
Throws
RangeError if the buffer is out of bounds
Defined in
readInt64()
readInt64(
littleEndian:boolean):bigint
Reads an unsigned 64-bit integer from the buffer.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| Whether the integer is little-endian |
Returns
bigint
Read value
Throws
RangeError if the buffer is out of bounds
Defined in
readUint64()
readUint64(
littleEndian:boolean):bigint
Reads a signed 64-bit integer from the buffer.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| Whether the integer is little-endian |
Returns
bigint
Read value
Throws
RangeError if the buffer is out of bounds
Defined in
readFloat32()
readFloat32(
littleEndian:boolean):number
Reads a 32-bit floating point number from the buffer.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| Whether the number is little-endian |
Returns
number
Read value
Throws
RangeError if the buffer is out of bounds
Defined in
readFloat64()
readFloat64(
littleEndian:boolean):number
Reads a 64-bit floating point number from the buffer.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| Whether the number is little-endian |
Returns
number
Read value
Throws
RangeError if the buffer is out of bounds
Defined in
readBytes()
readBytes(
byteLength:number):Uint8Array
Reads a set of bytes from the buffer.
Parameters
| Parameter | Type |
|---|---|
|
|
Returns
An Uint8Array containing the read bytes
Throws
RangeError if the buffer is out of bounds
Defined in
readBytesUnsafe()
readBytesUnsafe(
byteLength:number):Uint8Array
Reads a set of bytes from the buffer without copying.
Parameters
| Parameter | Type |
|---|---|
|
|
Returns
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
readArrayBuffer()
readArrayBuffer(
byteLength:number):ArrayBuffer
Reads an ArrayBuffer from the buffer.
Parameters
| Parameter | Type |
|---|---|
|
|
Returns
The read ArrayBuffer
Throws
RangeError if the buffer is out of bounds
Defined in
readTypedArray()
readTypedArray<
T>(TypedArray:TypedArrayConstructor<T>,elements:number):T
Reads a TypedArray from the buffer.
Type Parameters
| Type Parameter |
|---|
|
Parameters
| Parameter | Type | Description |
|---|---|---|
| The TypedArray constructor to use | |
|
| The number of elements to read |
Returns
T
The read TypedArray
Throws
RangeError if the buffer is out of bounds
Defined in
readString()
readString(
byteLength:number):string
Reads a string from the buffer.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| The number of bytes to read |
Returns
string
The read string
Throws
RangeError if the buffer is out of bounds
Defined in
readSchema()
readSchema<
T>(schema:T):InferSchemaType<T>
Reads a schema from the buffer.
Type Parameters
| Type Parameter |
|---|
|
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| The schema to read |
Returns
The value read from the buffer
Throws
RangeError if the buffer is out of bounds
Defined in
subarray()
subarray(
start:number,end:number):Uint8Array
Returns a subarray of the buffer.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| The start offset in bytes |
|
| The end offset in bytes |
Returns
The subarray
Remarks
The returned Uint8Array shares the same memory as the buffer.
Inherited from
Defined in
seek()
seek(
position:number):void
Seeks to a specific offset in the buffer.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| The offset to seek to |
Returns
void
Throws
RangeError if the position is out of bounds
Inherited from
Defined in
skip()
skip(
offset:number):void
Skips a number of bytes in the buffer.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| The number of bytes to skip |
Returns
void
Throws
RangeError if the offset is out of bounds
Inherited from
Defined in
Properties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
_buffer | protected | ArrayBufferLike | The underlying buffer. | ByteStream._buffer | byte-stream.ts:29 |
_view | protected | DataView | The DataView instance to read data from the buffer. | ByteStream._view | byte-stream.ts:34 |
_u8 | protected | Uint8Array | The Uint8Array instance to read data from the buffer. | ByteStream._u8 | byte-stream.ts:39 |
_offset | protected | number | The current offset in the buffer in bytes. | ByteStream._offset | byte-stream.ts:44 |