8000 Support streaming output (render_to(io)) — rubyzip can't stream · Issue #167 · urvin-compliance/caracal · GitHub
[go: up one dir, main page]

Skip to content

Support streaming output (render_to(io)) — rubyzip can't stream #167

Open

Description

@dlauer

Background

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:

rubyzip 1.3.0: Errno::ESPIPE: Illegal seek
rubyzip 3.6.0: Errno::ESPIPE: Illegal seek

(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

  1. Scope. Add streaming alongside rubyzip, or replace rubyzip entirely? Both writing (document.rb) and reading (document_renderer.rb, iframe_model.rb) are involved.
  2. API. Document.render_to(io) / #render_to(io) accepting anything that responds to <<, with render/save implemented on top.
  3. Compatibility. Keeping render returning a StringIO avoids breaking existing callers.
  4. Dependency. Swapping the zip backend would also end the recurring rubyzip constraint churn (rubyzip 1.1.2 not supported #118, rubyzip dependency #143, update rubyzip and bundler #158, Allow rubyzip 3.x (rubyzip < 3.4.0 has CVE-2026-85396) #165).

Tests should cover writing to a non-seekable IO and confirm the output still opens in Word.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0