Add files to a zip archive without having to re write the entire file?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Add files to a zip archive without having to re write the entire file?
Hi, I'm using info-zip to create zip archives. When i add files to an existing archive, the entire archive is re-written to a new temporary file and later is renamed. This means that if i have a big file and i want to add a small file to it, it will take a long time since the entire big file will be re-written. Is there any way to avoid this? like an option to append the new files to the existing archive? I've read a little about the zip archive format and it seems possible, since the zip central directory is stored at the end of the file. So theoretically you can append the last file and re-write only the zip central directory. I didn't find this option in info-zip, maybe i missed it? or maybe anyone knows another utility that can do this?
The "zip" and "unzip" utilities that come with Linux distributions are info-zip, and when you add files to an existing file, it re-writes the entire file to a temporary file, and finally renames it.
I think it has to create a new file and just can't add to the old one. Where it is doing it would be my guess memory unless you don't have enough. It isn't exactly like a tar process. A zip will recompute checksum. Pretty sure pk-zip did it that way a long time ago.
From man.
"When changing an existing zip archive, zip will write a temporary file with the new contents, and only replace the old one when the process of creating the new version has been completed without error."
As you can see from the time required to create and then to add a single file, it could have not been recreated.
Keep in mind that when recreating the file, zip does not need to re-compress the original files, just copy the already-compressed data. That is likely to take far less time than it took to create the original archive. Unlike gzip, which compresses the entire content as a single unit, zip independently compresses each file in the archive, and indeed the files in a single archive could use different compression methods.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.