Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Implement ZipWriter::new_streaming for unseekable writers #383

Closed
wants to merge 8 commits into from

Conversation

axnsan12
Copy link

This is a revival of #114 to implement unseekable writing via data descriptors.

No public API is changed except for the addition of ZipWriter::new_streaming, and all adjacent functionality still works - zip64, extra data, ZipCrypto encryption. I even fixed a bug where encryption was broken if used together with extra data :).

@chenxiaolong
Copy link

chenxiaolong commented Aug 25, 2023

Thanks a lot for implementing this!

I've been testing it quite a bit and it's been working very well. I only found a single issue where a panic occurs with the streaming ZipWriter when a non-zip64 small file entry is written such that the local header offset is >=2^32. I fixed it with: chenxiaolong@989101f.

The zip spec allows non-zip64 local headers to be written at offset
>=2^32 as long as the corresponding central directory entry has a zip64
extra field for the local header offset. However, when writing a
non-zip64 small file after the 2^32 boundary, `local_header_size()`
would return a zip64 size while writing a non-zip64 local header to
disk. This would cause `self.stats.start` to get out of sync, leading to
a panic in `finish_file()` when doing a checked subtraction for
`self.compressed_size`. This would only manifest when performing
streaming writes.

This commit fixes the problem by updating `local_header_size()` to use a
new `zip64_sizes()` method that only considers the compressed and
uncompressed size fields since only those two matter for determining the
size of a local header.

Signed-off-by: Andrew Gunnerson <[email protected]>
@Pr0methean
Copy link
Member

This repo is no longer maintained. Could you please rebase this against https://github.com/zip-rs/zip2 and reopen it there?

@Pr0methean Pr0methean closed this May 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants