Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port of features from miniz (creation of ZIP64 files and empty folders) #215

Merged
merged 2 commits into from
Dec 10, 2021

Conversation

javiserrano
Copy link
Contributor

Hello.

This pull request is a port of features from miniz that our company required for our usage of this library (many thanks for releasing it!). I think that they could be also useful to others, so here is a pull request for your consideration.

The code modified has been almost directly ported from this file:
https://github.com/richgel999/miniz/blob/master/miniz_zip.c

with minor changes to adapt the code to this project and simplify the port.

There are some points that I think that deserve to be commented:
a) This pull request makes the library to always create ZIP64 files
This has been forced with the flag MZ_ZIP_FLAG_WRITE_ZIP64 and has being done this way because the interface of the library doesn't require to know the number of files to ZIP or their size in advance (so initially we don't know if ZIP64 will be needed), and also because it eases the implementation.

b) Data descriptors (metadata after compressed data) are used to specify uncompresed size, compressed size and CRC
This is done using the flag MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR and it avoids the call to fseek that was needed to rewrite the header. This is optional in miniz. I have used this approach mainly because it allows to use the library in applications that doesn't have a working fseek like in our case, where we hook fopen, fwrite... to send out the data in streaming.

c) Empty folders are created calling zip_entry_open with a path ending with / followed by a call to zip_entry_close.
miniz just checks if the path ends with / to add the attribute MZ_ZIP_DOS_DIR_ATTRIBUTE_BITFLAG and throws an error if any data has been written, but I have added an extra check to not add the attribute if data has been written, to keep a better backwards compatibility with the current version of this library.

I have tested the changes creating a ZIP with 500.000 little files, another one with a file bigger than 5GB, and others with few files of different sizes and empty folders. I have been able to extract them on Linux, Windows and Mac with common tools on each platform (Nautilus, File Roller, WinRAR, and built-in decompressors) without problems.

@kuba--
Copy link
Owner

kuba-- commented Dec 10, 2021

@kuba--
Copy link
Owner

kuba-- commented Dec 10, 2021

Wow, thanks a lot @javiserrano !
I'm totally happy to merge this PR. It also closes https://github.com/kuba--/zip/issues/109.

Could you rebase with master. It should be trivial - mainly adding MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8 to mz_zip_writer_add_to_central_dir .

@kuba-- kuba-- added the zip64 Support for 64bit zip label Dec 10, 2021
@javiserrano
Copy link
Contributor Author

Of course!
Just one question. Shouldn't MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8 be also added to the local dir header?
I'm taking a look at miniz and it seems to use the same flags for both calls.
I could commit that change too in that case.

@kuba--
Copy link
Owner

kuba-- commented Dec 10, 2021

Just one question. Shouldn't MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8 be also added to the local dir header?

Yeah, I think it totally makes sense (I missed it). Thanks in advance.

Added MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8 to local dir header
@javiserrano
Copy link
Contributor Author

Done!

@kuba-- kuba-- merged commit a18b5b3 into kuba--:master Dec 10, 2021
thabetx pushed a commit to Symbyo360/zip that referenced this pull request Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
zip64 Support for 64bit zip
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants