Expand description
Reassemble newline-delimited frames across arbitrary network chunks.
Provider streams (SSE for OpenAI/Anthropic, NDJSON for Ollama) deliver
“one frame per line”. A single TCP/HTTP chunk can split a frame at any byte,
which the previous code did not handle — it ran text.lines() on each
chunk in isolation and silently dropped the trailing partial line, eating
characters mid-stream (e.g. “à rebours” arrived as “àours” because the
“reb” segment lived on the boundary).
LineBuffer is the minimal fix: feed it chunk bytes, get back the complete
lines that have accumulated. The unfinished tail stays inside the buffer
until the next chunk completes it.
Structs§
- Line
Buffer - Accumulates raw bytes and yields complete
\n-terminated lines. Partial trailing data is preserved across calls. Tolerates\r\nand mixed UTF-8 by accumulating bytes first and only converting to&strper complete line.