Skip to content

feat: add ZipFileBuilder for parallelizing compression - #911

Open
alex wants to merge 1 commit into
zip-rs:masterfrom
alex:zip-file-builder
Open

feat: add ZipFileBuilder for parallelizing compression#911
alex wants to merge 1 commit into
zip-rs:masterfrom
alex:zip-file-builder

Conversation

@alex

@alex alex commented Aug 8, 2026

Copy link
Copy Markdown

Compresses a file's contents independently of any ZipWriter, so that multiple files can be compressed on separate threads and then appended serially with ZipWriter::add_prepared_file.

Compresses a file's contents independently of any ZipWriter, so that
multiple files can be compressed on separate threads and then appended
serially with ZipWriter::add_prepared_file.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 8, 2026 13:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new “prepare then append” workflow to support parallelizing per-file compression work outside of ZipWriter, while still producing correct ZIP metadata when appending the pre-compressed payloads.

Changes:

  • Introduces ZipFileBuilder to compress a single file entry into memory while tracking CRC-32 and sizes, producing a PreparedZipFile.
  • Adds ZipWriter::add_prepared_file to append a PreparedZipFile by copying its already-compressed bytes verbatim (including handling ZIP64 header patching and stream/data-descriptor mode).
  • Adds tests covering roundtrip reading, duplicate-name rejection (and writer recovery), stream mode behavior, and encryption rejection.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Its-Just-Nans Its-Just-Nans left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

Thanks for the MR, a little question in comment.

Also, what do you think about adding a test with a thread (like the documentation)?

Comment thread src/write.rs
crc32: u32,
uncompressed_size: u64,
compressed_size: u64,
data: Vec<u8>,

@Its-Just-Nans Its-Just-Nans Aug 11, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using a Box<[u8]> ?

and change line 2526

-let data = cursor.into_inner();
+let data = cursor.into_inner().into_boxed_slice();

@alex

alex commented Aug 11, 2026

Copy link
Copy Markdown
Author

I originally had a test case with some threads (similar to the doc comment), but I removed it on the theory that the borrow checker meant it had to work :-) Happy to add it back.

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.

3 participants