Skip to content

ByteAccumulator

Defined in: packages/core/src/buffer/stream/byte-accumulator.ts:28

Growable byte arena with a read cursor — an incremental receive buffer for any producer/consumer pair where bytes arrive in arbitrary-sized chunks but must be consumed as a contiguous, possibly-partial window (a network receive path, a decompression sink, any stream reassembly).

Incoming chunks are copied once into a contiguous arena; consumed bytes only advance a read offset. Total copy cost is therefore linear in the number of bytes received, rather than the quadratic cost of concatenating the pending buffer with every arriving chunk.

view returns a window into the arena, not a copy. It is valid only until the next append or consume — compaction and growth both relocate live bytes. A consumer that retains any part of a view must copy it first.

new ByteAccumulator(maxSize, options?): ByteAccumulator

Defined in: packages/core/src/buffer/stream/byte-accumulator.ts:41

Construct a new accumulator with a maximum retained byte count. The arena will grow as needed, but append will throw if the retained byte count would exceed maxSize.

number

Maximum retained byte count; must be greater than zero.

ByteAccumulatorOptions

See ByteAccumulatorOptions.

ByteAccumulator

get buffered(): number

Defined in: packages/core/src/buffer/stream/byte-accumulator.ts:56

Number of unconsumed bytes currently held.

number


get capacity(): number

Defined in: packages/core/src/buffer/stream/byte-accumulator.ts:61

Current arena capacity, for diagnostics and tests.

number

append(chunk): void

Defined in: packages/core/src/buffer/stream/byte-accumulator.ts:71

Copy chunk into the arena, growing or compacting as needed.

Uint8Array

void

If the retained byte count would exceed the configured ceiling.


clear(): void

Defined in: packages/core/src/buffer/stream/byte-accumulator.ts:129

Discard everything held.

void


consume(count): void

Defined in: packages/core/src/buffer/stream/byte-accumulator.ts:105

Drop count bytes from the front.

number

void


take(): Uint8Array<ArrayBuffer>

Defined in: packages/core/src/buffer/stream/byte-accumulator.ts:121

Copy out the unconsumed bytes and reset. Used to hand residue to another consumer across a protocol/format switch.

Uint8Array<ArrayBuffer>


view(): Uint8Array<ArrayBuffer>

Defined in: packages/core/src/buffer/stream/byte-accumulator.ts:100

Window over the unconsumed bytes. Invalidated by the next append or consume; copy before retaining.

Uint8Array<ArrayBuffer>