Skip to main content

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

ArrayBuffer

Inherited from

BufferView.buffer

Defined in

buffer-view.ts:75


view

Get Signature

get view(): DataView

Returns the underlying DataView instance

Returns

DataView

Inherited from

BufferView.view

Defined in

buffer-view.ts:82


position

Get Signature

get position(): number

Returns the current offset in the buffer in bytes.

Returns

number

Inherited from

BufferView.position

Defined in

buffer-view.ts:89


capacity

Get Signature

get capacity(): number

The current capacity of the buffer.

Returns

number

Defined in

buffer-writer.ts:143


remaining

Get Signature

get remaining(): number

The remaining space in the buffer in bytes.

Returns

number

Defined in

buffer-writer.ts:150

Constructors

new BufferWriter()

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

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

BufferWriter

Throws

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

Overrides

BufferView.constructor

Defined in

buffer-writer.ts:104

Methods

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

BufferView.subarray

Defined in

buffer-view.ts:46


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

BufferView.seek

Defined in

buffer-view.ts:55


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

BufferView.skip

Defined in

buffer-view.ts:68


reserve()

protected 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

buffer-writer.ts:123


reset()

reset(): void

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

Returns

void

Defined in

buffer-writer.ts:157


commit()

commit(): ArrayBuffer

Commits the buffer.

Returns

ArrayBuffer

The ArrayBuffer containing the written data

Defined in

buffer-writer.ts:165


commitUint8Array()

commitUint8Array(): Uint8Array

Commits the buffer as a Uint8Array.

Returns

Uint8Array

The Uint8Array containing the written data

Defined in

buffer-writer.ts:173


toUint8Array()

toUint8Array(): Uint8Array

Converts the buffer to a Uint8Array.

Returns

Uint8Array

The Uint8Array containing the written data

Defined in

buffer-writer.ts:181


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

buffer-writer.ts:190


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

buffer-writer.ts:201


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

buffer-writer.ts:213


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

buffer-writer.ts:225


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

buffer-writer.ts:237


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

buffer-writer.ts:249


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

buffer-writer.ts:261


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

buffer-writer.ts:273


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

buffer-writer.ts:285


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

buffer-writer.ts:297


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

buffer-writer.ts:309

Properties

PropertyModifierTypeDescriptionInherited fromDefined in
_bufferprotectedArrayBufferThe underlying buffer.BufferView._bufferbuffer-view.ts:9
_viewprotectedDataViewThe DataView instance to read data from the buffer.BufferView._viewbuffer-view.ts:14
_u8protectedUint8ArrayThe Uint8Array instance to read data from the buffer.BufferView._u8buffer-view.ts:19
_offsetprotectednumberThe current offset in the buffer in bytes.BufferView._offsetbuffer-view.ts:24
_optionsprotectedResizeOptionsThe options for buffer resizing.-buffer-writer.ts:91
_resizeFnprotectedResizeFnThe function for resizing the buffer.-buffer-writer.ts:96