BlockAccumulator
Defined in: packages/core/src/buffer/stream/block-accumulator.ts:30
Buffers arbitrary-length writes into fixed-size blocks, invoking
processBlock once per full block, and carrying any sub-block remainder
across calls.
The general shape behind any incremental, block-oriented consumer of a byte stream (block ciphers, block-based hash functions, framed protocols, …): accumulate the previous remainder plus the new chunk, process every full block that yields, and keep whatever is left over for next time.
By default (holdBackFinalBlock: false) a block is flushed as soon as it
completes — correct whenever finalization can unambiguously recognise the
true final block from the data itself (e.g. Merkle–Damgård/Keccak padding,
which always appends a marker byte, so nothing already flushed can be
mistaken for it). Pass holdBackFinalBlock: true for algorithms whose
finalization instead flips a flag at compress-time with no marker in the data
(BLAKE2): then the last full block a chunk completes is always kept back,
since flushing it immediately would leave no way to later mark it final
without compressing it twice.
Example
Section titled “Example” const acc = new BlockAccumulator(4, (block, offset) => console.log(block.subarray(offset, offset + 4)), ); acc.absorb(new Uint8Array([1, 2, 3])); // buffered, no full block yet acc.absorb(new Uint8Array([4, 5])); // logs [1,2,3,4]; tail is now [5] ```;
## Constructors
### Constructor
> **new BlockAccumulator**(`blockSizeBytes`, `processBlock`, `holdBackFinalBlock?`): `BlockAccumulator`
Defined in: packages/core/src/buffer/stream/block-accumulator.ts:41
#### Parameters
##### blockSizeBytes
`number`
The fixed block size `processBlock` is called with.
##### processBlock
(`block`, `offset`) => `void`
Invoked once per full block, in order, never with a partial block.
##### holdBackFinalBlock?
`boolean` = `false`
When `true`, the last full block a chunk completes is kept in `tail` rather than flushed immediately — see the class doc above.
#### Returns
`BlockAccumulator`
## Accessors
### tail
#### Get Signature
> **get** **tail**(): `Uint8Array`\<`ArrayBuffer`\>
Defined in: packages/core/src/buffer/stream/block-accumulator.ts:48
The bytes buffered since the last full block, not yet processed.
##### Returns
`Uint8Array`\<`ArrayBuffer`\>
## Methods
### absorb()
> **absorb**(`chunk`): `void`
Defined in: packages/core/src/buffer/stream/block-accumulator.ts:58
Buffers `chunk`, processing every full block it completes.
#### Parameters
##### chunk
`Uint8Array`
#### Returns
`void`
***
### clear()
> **clear**(): `void`
Defined in: packages/core/src/buffer/stream/block-accumulator.ts:53
Discard everything held, without processing it.
#### Returns
`void`