Skip to main content

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​

ArrayBuffer

Overrides​

ByteStream.buffer

Defined in​

byte-stream-writer.ts:188


capacity​

Get Signature​

get capacity(): number

The current capacity of the buffer.

Returns​

number

Defined in​

byte-stream-writer.ts:195


remaining​

Get Signature​

get remaining(): number

The remaining space in the buffer in bytes.

Returns​

number

Defined in​

byte-stream-writer.ts:202


view​

Get Signature​

get view(): DataView

Returns the underlying DataView instance

Returns​

DataView

Inherited from​

ByteStream.view

Defined in​

byte-stream.ts:116


position​

Get Signature​

get position(): number

Returns the current offset in the buffer in bytes.

Returns​

number

Inherited from​

ByteStream.position

Defined in​

byte-stream.ts:123

Constructors​

new ByteStreamWriter()​

new ByteStreamWriter(byteLength: number, options?: Partial<ResizeOptions>): ByteStreamWriter

Creates a new buffer writer.

Parameters​

ParameterTypeDescription

byteLength

number

The initial byte length of the buffer

options?

Partial<ResizeOptions>

The options for buffer resizing

Returns​

ByteStreamWriter

Throws​

RangeError if the initial buffer size is invalid or the maxByteLength is less than the initial buffer size

Overrides​

ByteStream.constructor

Defined in​

byte-stream-writer.ts:124

new ByteStreamWriter()​

new ByteStreamWriter(buffer: ArrayBufferLike): ByteStreamWriter

Creates a new buffer writer.

Parameters​

ParameterTypeDescription

buffer

ArrayBufferLike

The buffer to write to

Returns​

ByteStreamWriter

Throws​

RangeError if the initial buffer size is invalid or the maxByteLength is less than the initial buffer size

Overrides​

ByteStream.constructor

Defined in​

byte-stream-writer.ts:131

new ByteStreamWriter()​

new ByteStreamWriter(typedArray: TypedArray): ByteStreamWriter

Creates a new buffer writer.

Parameters​

ParameterTypeDescription

typedArray

TypedArray

The TypedArray to use an underlying buffer for writing

Returns​

ByteStreamWriter

Throws​

RangeError if the initial buffer size is invalid or the maxByteLength is less than the initial buffer size

Overrides​

ByteStream.constructor

Defined in​

byte-stream-writer.ts:138

Methods​

reserve()​

reserve(byteLength: number): void

Reserves space in the buffer.

Parameters​

ParameterTypeDescription

byteLength

number

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​

byte-stream-writer.ts:168


reset()​

reset(): void

Resets the buffer offset to zero, allowing to write from the beginning.

Returns​

void

Defined in​

byte-stream-writer.ts:209


commit()​

commit(): any

Commits the buffer.

Returns​

any

The Uint8Array containing the written data

Defined in​

byte-stream-writer.ts:217


toUint8Array()​

toUint8Array(): any

Converts the buffer to a Uint8Array.

Returns​

any

The Uint8Array containing the written data

Defined in​

byte-stream-writer.ts:225


writeUint8()​

writeUint8(value: number): void

Writes an unsigned 8-bit integer to the buffer.

Parameters​

ParameterTypeDescription

value

number

The value to write

Returns​

void

Throws​

RangeError if buffer is full and not resizable or has reached its maximum capacity

Defined in​

byte-stream-writer.ts:234


writeInt8()​

writeInt8(value: number): void

Writes a signed 8-bit integer to the buffer.

Parameters​

ParameterTypeDescription

value

number

The value to write

Returns​

void

Throws​

RangeError if buffer is full and not resizable or has reached its maximum capacity

Defined in​

byte-stream-writer.ts:245


writeUint16()​

writeUint16(value: number, littleEndian: boolean): void

Writes an unsigned 16-bit integer to the buffer.

Parameters​

ParameterTypeDescription

value

number

The value to write

littleEndian

boolean

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​

byte-stream-writer.ts:257


writeInt16()​

writeInt16(value: number, littleEndian: boolean): void

Writes a signed 16-bit integer to the buffer.

Parameters​

ParameterTypeDescription

value

number

The value to write

littleEndian

boolean

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​

byte-stream-writer.ts:269


writeUint32()​

writeUint32(value: number, littleEndian: boolean): void

Writes an unsigned 32-bit integer to the buffer.

Parameters​

ParameterTypeDescription

value

number

The value to write

littleEndian

boolean

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​

byte-stream-writer.ts:281


writeInt32()​

writeInt32(value: number, littleEndian: boolean): void

Writes a signed 32-bit integer to the buffer.

Parameters​

ParameterTypeDescription

value

number

The value to write

littleEndian

boolean

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​

byte-stream-writer.ts:293


writeInt64()​

writeInt64(value: bigint, littleEndian: boolean): void

Writes an unsigned 64-bit integer to the buffer.

Parameters​

ParameterTypeDescription

value

bigint

The value to write

littleEndian

boolean

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​

byte-stream-writer.ts:305


writeUint64()​

writeUint64(value: bigint, littleEndian: boolean): void

Writes an unsigned 64-bit integer to the buffer.

Parameters​

ParameterTypeDescription

value

bigint

The value to write

littleEndian

boolean

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​

byte-stream-writer.ts:317


writeFloat32()​

writeFloat32(value: number, littleEndian: boolean): void

Writes a 32-bit float to the buffer.

Parameters​

ParameterTypeDescription

value

number

The value to write

littleEndian

boolean

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​

byte-stream-writer.ts:329


writeFloat64()​

writeFloat64(value: number, littleEndian: boolean): void

Writes a 64-bit float to the buffer.

Parameters​

ParameterTypeDescription

value

number

The value to write

littleEndian

boolean

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​

byte-stream-writer.ts:341


writeBytes()​

writeBytes(src: Uint8Array, byteLength?: number): void

Writes bytes to the buffer.

Parameters​

ParameterTypeDescription

src

Uint8Array

The source buffer to write

byteLength?

number

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​

byte-stream-writer.ts:353


writeArrayBuffer()​

writeArrayBuffer(value: ArrayBuffer): void

Writes an ArrayBuffer to the buffer.

Parameters​

ParameterTypeDescription

value

ArrayBuffer

The ArrayBuffer to write

Returns​

void

Throws​

RangeError if buffer is full and not resizable or has reached its maximum capacity

Defined in​

byte-stream-writer.ts:366


writeTypedArray()​

writeTypedArray<T>(value: T): void

Writes a TypedArray to the buffer.

Type Parameters​

Type Parameter

T extends TypedArray

Parameters​

ParameterTypeDescription

value

T

The TypedArray to write

Returns​

void

Throws​

RangeError if buffer is full and not resizable or has reached its maximum capacity

Defined in​

byte-stream-writer.ts:375


writeString()​

writeString(value: string, byteLength: number): number

Writes a string to the buffer.

Parameters​

ParameterTypeDescription

value

string

The string to write

byteLength

number

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​

byte-stream-writer.ts:386


writeSchema()​

writeSchema<T>(schema: T, value: InferSchemaType<T>): void

Writes a schema to the buffer.

Type Parameters​

Type Parameter

T extends SchemaLike<unknown, ByteStream, ByteStream>

Parameters​

ParameterTypeDescription

schema

T

The schema to write

value

InferSchemaType<T>

The schema value to write

Returns​

void

Throws​

RangeError if buffer is full and not resizable or has reached its maximum capacity

Defined in​

byte-stream-writer.ts:465


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​

ByteStream.subarray

Defined in​

byte-stream.ts:80


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​

ByteStream.seek

Defined in​

byte-stream.ts:89


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​

ByteStream.skip

Defined in​

byte-stream.ts:102

Properties​

PropertyModifierTypeDescriptionOverridesInherited fromDefined in
_bufferprotectedArrayBufferThe underlying buffer.ByteStream._buffer-byte-stream-writer.ts:106
_optionsprotectedResizeOptionsThe options for buffer resizing.--byte-stream-writer.ts:111
_resizeFnprotectedResizeFnThe function for resizing the buffer.--byte-stream-writer.ts:116
_viewprotectedDataViewThe DataView instance to read data from the buffer.-ByteStream._viewbyte-stream.ts:34
_u8protectedUint8ArrayThe Uint8Array instance to read data from the buffer.-ByteStream._u8byte-stream.ts:39
_offsetprotectednumberThe current offset in the buffer in bytes.-ByteStream._offsetbyte-stream.ts:44