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:183


capacity

Get Signature

get capacity(): number

The current capacity of the buffer.

Returns

number

Defined in

byte-stream-writer.ts:190


remaining

Get Signature

get remaining(): number

The remaining space in the buffer in bytes.

Returns

number

Defined in

byte-stream-writer.ts:197


view

Get Signature

get view(): DataView

Returns the underlying DataView instance

Returns

DataView

Inherited from

ByteStream.view

Defined in

byte-stream.ts:110


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:117

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:119

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:126

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:133

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:163


reset()

reset(): void

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

Returns

void

Defined in

byte-stream-writer.ts:204


commit()

commit(): any

Commits the buffer.

Returns

any

The Uint8Array containing the written data

Defined in

byte-stream-writer.ts:212


toUint8Array()

toUint8Array(): any

Converts the buffer to a Uint8Array.

Returns

any

The Uint8Array containing the written data

Defined in

byte-stream-writer.ts:220


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:229


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:240


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:252


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:264


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:276


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:288


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:300


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:312


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:324


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:336


writeBytes()

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

Writes bytes to the buffer.

Parameters

ParameterTypeDescription

src

Uint8Array

The source buffer to write from

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:348


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:362


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:74


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:83


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:96

Properties

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