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 lifetime
Section titled “View lifetime”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.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”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.
Parameters
Section titled “Parameters”maxSize
Section titled “maxSize”number
Maximum retained byte count; must be greater than zero.
options?
Section titled “options?”Returns
Section titled “Returns”ByteAccumulator
Accessors
Section titled “Accessors”buffered
Section titled “buffered”Get Signature
Section titled “Get Signature”get buffered():
number
Defined in: packages/core/src/buffer/stream/byte-accumulator.ts:56
Number of unconsumed bytes currently held.
Returns
Section titled “Returns”number
capacity
Section titled “capacity”Get Signature
Section titled “Get Signature”get capacity():
number
Defined in: packages/core/src/buffer/stream/byte-accumulator.ts:61
Current arena capacity, for diagnostics and tests.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”append()
Section titled “append()”append(
chunk):void
Defined in: packages/core/src/buffer/stream/byte-accumulator.ts:71
Copy chunk into the arena, growing or compacting as needed.
Parameters
Section titled “Parameters”Uint8Array
Returns
Section titled “Returns”void
Throws
Section titled “Throws”If the retained byte count would exceed the configured ceiling.
clear()
Section titled “clear()”clear():
void
Defined in: packages/core/src/buffer/stream/byte-accumulator.ts:129
Discard everything held.
Returns
Section titled “Returns”void
consume()
Section titled “consume()”consume(
count):void
Defined in: packages/core/src/buffer/stream/byte-accumulator.ts:105
Drop count bytes from the front.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
take()
Section titled “take()”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.
Returns
Section titled “Returns”Uint8Array<ArrayBuffer>
view()
Section titled “view()”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.
Returns
Section titled “Returns”Uint8Array<ArrayBuffer>