Skip to main content

Editor.Buffer

Class

Wraps a byte array for data serialization and deserialization.

Index

Example

const bytes = new Uint8Array([72, 101, 108, 108, 111]); // "Hello"
const buffer = new Editor.Buffer(bytes);

// Round-trip: toBytes() recovers the original byte array
const roundTripped = buffer.toBytes();
const matches = roundTripped.every((b: number, i: number) => b === bytes[i]);

console.log(`Buffer "${buffer.toString()}" (${roundTripped.length} bytes), round-trip match: ${matches}`);

Constructors

Constructor

new Buffer(bytes): Buffer

Create a buffer from a byte array.

Parameters

ParameterType
bytesUint8Array

Returns

Buffer

Methods

toBytes()

toBytes(): Uint8Array

Return the underlying byte array.

Returns

Uint8Array


toString()

toString(): string

Return the buffer contents as a UTF-8 string.

Returns

string