Skip to content

Streaming

All WriteXxx functions stream directly via standard Go encoders:

// JSON — streams via json.Encoder
err := serialization.WriteJSON(os.Stdout, data)
// CSV — streams row-by-row via csv.Writer
err := delimited.WriteCSV(os.Stdout, data)
// YAML — streams via yaml.Encoder
err := serialization.WriteYAML(os.Stdout, data)

No intermediate []byte or string allocation. The standard encoders add a trailing \n (canonical Go behavior).

For very large HTML tables, use the streaming renderer:

renderer := markup.NewStreamingHTMLRenderer()
renderer.SetData(data)
err := renderer.Stream(os.Stdout)

This writes the HTML table incrementally, keeping memory usage flat regardless of row count.

For line-delimited JSON (ideal for log streams and event sourcing):

writer := serialization.NewJSONLWriter(os.Stdout)
for _, item := range items {
_ = writer.Encode(item)
}

Each call to Encode writes one JSON object followed by a newline.

Since v0.30.0, output.RenderTable uses the same streaming encoders as the CQRS API. This means:

// These two produce byte-for-byte identical output:
serialization.WriteJSON(os.Stdout, data)
output.RenderTable(data, output.FormatJSON, output.RenderOptions{})

Both stream via json.Encoder, both append a trailing \n.