You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support streaming output (render_to(io)) — rubyzip can't stream #167
Caracal buffers the whole .docx in memory: Document#render builds a StringIO via Zip::OutputStream.write_buffer, and #save writes that buffer out. For large documents this holds the entire file in memory, and it can't be written incrementally to a socket or an HTTP response.
rubyzip can't do this
Suggesting a render_to(io) built on rubyzip's OutputStream (as I did when closing #126) was wrong. rubyzip seeks back to rewrite local headers as it finalizes each entry, so a non-seekable output fails. Verified on Ruby 3.3:
(writing to an IO.pipe writer via Zip::OutputStream.write_buffer)
So streaming requires a zip writer that emits data descriptors instead of backfilling headers.
Option: zip_kit
@julik's #126 implemented exactly this with zip_tricks, which is now zip_kit (6.3.4, MIT). #126 is the reference implementation and worth reading before anyone starts: it added Document.render_to(writable) and a small ZipReader adapter, since iframes also read zips.
Things to decide
Scope. Add streaming alongside rubyzip, or replace rubyzip entirely? Both writing (document.rb) and reading (document_renderer.rb, iframe_model.rb) are involved.
API.Document.render_to(io) / #render_to(io) accepting anything that responds to <<, with render/save implemented on top.
Compatibility. Keeping render returning a StringIO avoids breaking existing callers.
Activity