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
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 BufferReader()
new BufferReader(
buffer
:ArrayBuffer
):BufferReader
Creates a new buffer view.
Parameters
Parameter | Type | Description |
---|---|---|
| The buffer 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
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 | ArrayBuffer | The underlying buffer. | BufferView ._buffer | buffer-view.ts:9 |
_view | protected | DataView | The DataView instance to read data from the buffer. | BufferView ._view | buffer-view.ts:14 |
_u8 | protected | Uint8Array | The Uint8Array instance to read data from the buffer. | BufferView ._u8 | buffer-view.ts:19 |
_offset | protected | number | The current offset in the buffer in bytes. | BufferView ._offset | buffer-view.ts:24 |