Streaming
Write and read tables a row at a time. Memory stays flat whether you have a thousand rows or ten million.
Write
from jdogo import JDogoStreamWriter
with open("events.jdogo", "w", encoding="utf-8") as f:
w = JDogoStreamWriter(f)
w.write_header("id", "type", "ms")
for e in events:
w.write_row(e)
w.flush()import { DocStreamWriter } from "jdogo";
const w = new DocStreamWriter();
out.write(w.header(["id", "type", "ms"]));
for (const e of events) out.write(w.row(e));try (var w = new JDogoStreamWriter(Files.newBufferedWriter(path))) {
w.writeHeader("id", "type", "ms");
for (var e : events) w.writeRow(e); // a Map, or values in header order
}Read
from jdogo import JDogoStreamReader
with open("events.jdogo", encoding="utf-8") as f:
for row in JDogoStreamReader(f):
handle(row)import { DocStreamReader } from "jdogo";
const r = new DocStreamReader();
for await (const chunk of stream) {
for (const row of r.feed(chunk)) handle(row); // text arrives in any pieces
}
for (const row of r.end()) handle(row);try (var r = new JDogoStreamReader(Files.newBufferedReader(path))) {
for (var row : r) handle(row);
}Rules
- Streaming readers return exactly what the document decoder would.
- Writers use the same cell rules as the encoder, without column optimizations, so output is somewhat larger than
dumps. - A row with a key that isn't a column is refused rather than dropped.
- Readers accept any table (
@header); record lines (@:) are for prompts and aren't streamed.
Model output, as it streams
When a model writes JDogo rows, feed its token stream to DocStreamReader and act on each complete row before the reply finishes. The Vercel AI SDK helper wraps this for web streams; see Integrations.