Skip to content

Add streaming Writer support (html-write, page-write)#36

Open
escherize wants to merge 1 commit intomasterfrom
streaming-writer-support
Open

Add streaming Writer support (html-write, page-write)#36
escherize wants to merge 1 commit intomasterfrom
streaming-writer-support

Conversation

@escherize
Copy link
Owner

@escherize escherize commented Feb 28, 2026

Summary

  • Extracts a private emit-parsed! helper that centralizes parse -> validate -> emit logic
  • Refactors html to delegate to emit-parsed! (behavioral no-op, all existing tests pass)
  • Adds html-write and page-write that write directly to a java.io.Writer instead of building a string in memory

This enables faster time-to-first-byte and lower memory usage for large or lazily-generated pages. The approach works because all emit multimethods already write exclusively through an append! function argument — streaming support just provides a different append! that writes to a Writer.

Design decisions

  • Writer not OutputStream: HTML is characters, not bytes. Callers wrap OutputStream in OutputStreamWriter (one-liner)
  • Writer-first arg order: follows spit+io/copy convention
  • No auto-flush: caller controls flushing; auto-flushing on every append would destroy buffered-writer performance
  • No changes to existing API html and page behave identically

Closes #35

Test plan

  • All 35 existing tests pass (180 assertions, 0 failures)
  • New html-write-test: basic output, equivalence with html, opts passthrough, component support
  • New page-write-test: doctype prefix + content

Extract emit-parsed! helper from html, then add html-write and
page-write that write directly to a java.io.Writer instead of
building a string in memory. Enables faster time-to-first-byte
and lower memory usage for large pages.

Closes #35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streaming support?

1 participant