Class: BufferWriter
A class that provides methods for writing binary data to 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
capacity
Get Signature
get capacity():
number
The current capacity of the buffer.
Returns
number
Defined in
remaining
Get Signature
get remaining():
number
The remaining space in the buffer in bytes.
Returns
number
Defined in
Constructors
new BufferWriter()
new BufferWriter(
byteLength
:number
,options
:Partial
<ResizeOptions
>):BufferWriter
Creates a new buffer writer.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The initial byte length of the buffer |
| The options for buffer resizing |
Returns
Throws
RangeError if the initial buffer size is invalid or the maxByteLength is less than the initial buffer size
Overrides
Defined in
Methods
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
reserve()
protected
reserve(byteLength
:number
):void
Reserves space in the buffer.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The number of bytes to reserve |
Returns
void
Throws
RangeError if the buffer is not resizable and the reserved space exceeds the buffer capacity
Defined in
reset()
reset():
void
Resets the buffer offset to zero, allowing to write from the beginning.
Returns
void
Defined in
commit()
commit():
ArrayBuffer
Commits the buffer.
Returns
The ArrayBuffer containing the written data
Defined in
commitUint8Array()
commitUint8Array():
Uint8Array
Commits the buffer as a Uint8Array.
Returns
The Uint8Array containing the written data
Defined in
toUint8Array()
toUint8Array():
Uint8Array
Converts the buffer to a Uint8Array.
Returns
The Uint8Array containing the written data
Defined in
writeUint8()
writeUint8(
value
:number
):void
Writes an unsigned 8-bit integer to the buffer.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The value to write |
Returns
void
Throws
RangeError if buffer is full and not resizable or has reached its maximum capacity
Defined in
writeInt8()
writeInt8(
value
:number
):void
Writes a signed 8-bit integer to the buffer.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The value to write |
Returns
void
Throws
RangeError if buffer is full and not resizable or has reached its maximum capacity
Defined in
writeUint16()
writeUint16(
value
:number
,littleEndian
:boolean
):void
Writes an unsigned 16-bit integer to the buffer.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The value to write |
|
| Whether the integer is little-endian |
Returns
void
Throws
RangeError if buffer is full and not resizable or has reached its maximum capacity
Defined in
writeInt16()
writeInt16(
value
:number
,littleEndian
:boolean
):void
Writes a signed 16-bit integer to the buffer.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The value to write |
|
| Whether the integer is little-endian |
Returns
void
Throws
RangeError if buffer is full and not resizable or has reached its maximum capacity
Defined in
writeUint32()
writeUint32(
value
:number
,littleEndian
:boolean
):void
Writes an unsigned 32-bit integer to the buffer.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The value to write |
|
| Whether the integer is little-endian |
Returns
void
Throws
RangeError if buffer is full and not resizable or has reached its maximum capacity
Defined in
writeInt32()
writeInt32(
value
:number
,littleEndian
:boolean
):void
Writes a signed 32-bit integer to the buffer.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The value to write |
|
| Whether the integer is little-endian |
Returns
void
Throws
RangeError if buffer is full and not resizable or has reached its maximum capacity
Defined in
writeInt64()
writeInt64(
value
:bigint
,littleEndian
:boolean
):void
Writes an unsigned 64-bit integer to the buffer.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The value to write |
|
| Whether the integer is little-endian |
Returns
void
Throws
RangeError if buffer is full and not resizable or has reached its maximum capacity
Defined in
writeUint64()
writeUint64(
value
:bigint
,littleEndian
:boolean
):void
Writes an unsigned 64-bit integer to the buffer.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The value to write |
|
| Whether the integer is little-endian |
Returns
void
Throws
RangeError if buffer is full and not resizable or has reached its maximum capacity
Defined in
writeFloat32()
writeFloat32(
value
:number
,littleEndian
:boolean
):void
Writes a 32-bit float to the buffer.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The value to write |
|
| Whether the float is little-endian |
Returns
void
Throws
RangeError if buffer is full and not resizable or has reached its maximum capacity
Defined in
writeFloat64()
writeFloat64(
value
:number
,littleEndian
:boolean
):void
Writes a 64-bit float to the buffer.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The value to write |
|
| Whether the float is little-endian |
Returns
void
Throws
RangeError if buffer is full and not resizable or has reached its maximum capacity
Defined in
writeBytes()
writeBytes(
src
:Uint8Array
,byteLength
?:number
):void
Writes bytes to the buffer.
Parameters
Parameter | Type | Description |
---|---|---|
| The source buffer to write from | |
|
| The number of bytes to write |
Returns
void
Throws
RangeError if buffer is full and not resizable or has reached its maximum capacity
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 |
_options | protected | ResizeOptions | The options for buffer resizing. | - | buffer-writer.ts:91 |
_resizeFn | protected | ResizeFn | The function for resizing the buffer. | - | buffer-writer.ts:96 |