Class: ByteStreamWriter
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
Overrides
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
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 ByteStreamWriter()
new ByteStreamWriter(
byteLength:number,options?:Partial<ResizeOptions>):ByteStreamWriter
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
new ByteStreamWriter()
new ByteStreamWriter(
buffer:ArrayBufferLike):ByteStreamWriter
Creates a new buffer writer.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| The buffer to write to |
Returns
Throws
RangeError if the initial buffer size is invalid or the maxByteLength is less than the initial buffer size
Overrides
Defined in
new ByteStreamWriter()
new ByteStreamWriter(
typedArray:TypedArray):ByteStreamWriter
Creates a new buffer writer.
Parameters
| Parameter | Type | Description |
|---|---|---|
| The TypedArray to use an underlying buffer for writing |
Returns
Throws
RangeError if the initial buffer size is invalid or the maxByteLength is less than the initial buffer size
Overrides
ByteStream.constructor
Defined in
Methods
reserve()
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():
any
Commits the buffer.
Returns
any
The Uint8Array containing the written data
Defined in
toUint8Array()
toUint8Array():
any
Converts the buffer to a Uint8Array.
Returns
any
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 | |
|
| 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
writeArrayBuffer()
writeArrayBuffer(
value:ArrayBuffer):void
Writes an ArrayBuffer to the buffer.
Parameters
| Parameter | Type | Description |
|---|---|---|
| The ArrayBuffer to write |
Returns
void
Throws
RangeError if buffer is full and not resizable or has reached its maximum capacity
Defined in
writeTypedArray()
writeTypedArray<
T>(value:T):void
Writes a TypedArray to the buffer.
Type Parameters
| Type Parameter |
|---|
|
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| The TypedArray to write |
Returns
void
Throws
RangeError if buffer is full and not resizable or has reached its maximum capacity
Defined in
writeString()
writeString(
value:string,byteLength:number):number
Writes a string to the buffer.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| The string to write |
|
| The number of bytes to write |
Returns
number
The number of characters written
Throws
RangeError if buffer is full and not resizable or has reached its maximum capacity
Defined in
writeSchema()
writeSchema<
T>(schema:T,value:InferSchemaType<T>):void
Writes a schema to the buffer.
Type Parameters
| Type Parameter |
|---|
|
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| The schema to write |
| The schema value to write |
Returns
void
Throws
RangeError if buffer is full and not resizable or has reached its maximum capacity
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 | Overrides | Inherited from | Defined in |
|---|---|---|---|---|---|---|
_buffer | protected | ArrayBuffer | The underlying buffer. | ByteStream._buffer | - | byte-stream-writer.ts:106 |
_options | protected | ResizeOptions | The options for buffer resizing. | - | - | byte-stream-writer.ts:111 |
_resizeFn | protected | ResizeFn | The function for resizing the buffer. | - | - | byte-stream-writer.ts:116 |
_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 |