Skip to content
1 min read · 171 words

Function: createNdjsonLineReader()

ts
function createNdjsonLineReader<T>(
  onLine: (raw: string) => T | undefined,
  opts?: {
    maxLineBytes?: number;
  },
): {
  end: void;
  push: void;
};

Defined in: src/batteries/llm/claude_code_cli/wire.ts:308

Create an incremental, byte-oriented NDJSON line reader. Generalizes local_diffusion/protocol.ts's createFrameReader discipline (bounded memory via a hard maxLineBytes cap enforced while consuming, fatal-UTF8-decode, malformed-line-is-non-fatal) for pure JSON-per-line framing with no tag-prefixed grammar. onLine receives each decoded line and returns the parsed value, or undefined for a line that failed to parse — the reader itself never throws and never classifies content, it only frames bytes into lines.

Type Parameters

Type Parameter
T

Parameters

ParameterType
onLine(raw: string) => T | undefined
opts?{ maxLineBytes?: number; }
opts.maxLineBytes?number

Returns

ts
{
  end: void;
  push: void;
}
NameTypeDefined in
end()() => voidsrc/batteries/llm/claude_code_cli/wire.ts:311
push()(chunk: Uint8Array) => voidsrc/batteries/llm/claude_code_cli/wire.ts:311

Throws

RangeError if maxLineBytes is provided but is not a positive, finite, safe integer.