Function: createFrameReader()
function createFrameReader(opts: {
config?: ProtocolConfig;
maxLineBytes?: number;
onFrame: void;
}): {
end: void;
push: void;
};Defined in: src/batteries/generation/local_diffusion/protocol.ts:367
Create an incremental, byte-oriented line reader. Raw bytes are retained (never a decoded string), the maxLineBytes cap is enforced while consuming so an unbounded no-newline write cannot balloon memory, an over-sized physical line reports exactly one protocolError and is then discarded through its next newline (its continuation is NOT re-parsed as a fresh frame), and each bounded, complete line is decoded with a fatal UTF-8 decoder — invalid encoding yields a malformed frame. Malformed protocol lines are reported as malformed rather than thrown.
Pending bytes of an in-progress line are held as a queue of chunk SEGMENTS with a running byte count, and concatenated exactly once when the line's terminator arrives — so many small fragments of one line cost O(line length) total, not O(line length²) (terra v2 #4).
Parameters
| Parameter | Type |
|---|---|
opts | { config?: ProtocolConfig; maxLineBytes?: number; onFrame: void; } |
opts.config? | ProtocolConfig |
opts.maxLineBytes? | number |
opts.onFrame |
Returns
{
end: void;
push: void;
}| Name | Type | Defined in |
|---|---|---|
end() | () => void | src/batteries/generation/local_diffusion/protocol.ts:371 |
push() | (chunk: Uint8Array) => void | src/batteries/generation/local_diffusion/protocol.ts:371 |
Throws
RangeError if maxLineBytes is provided but is not a positive, finite, safe integer — an unvalidated Infinity/NaN/negative would silently defeat the bounded-memory guarantee (terra v2 #3).