Kaushik Wavhal
Kaushik Wavhal

Reputation: 720

why can't a zip file be modified without re-zipping the entire file?

Modifying or altering a zip file essentially cannot be done on the same file. To be able to do that, the old file along with the new changes are put into a new zip file by re-zipping the entire content. I wanted to know why is this necessary? Why can't a zip file be modified without re-zipping the entire file again ?

Upvotes: 2

Views: 963

Answers (2)

Mark Adler
Mark Adler

Reputation: 112482

The zip file format was designed to permit modifying entries (changing, deleting, adding) without having to recompress the other entries. So you have it all wrong. You just need to copy part or all of the zip file contents over in the same file or a different file, but you do not need to recompress the unchanged entries.

Upvotes: 1

Ambyjkl
Ambyjkl

Reputation: 440

After a bit of research, it seems this is not the case. Zip files in fact do allow you to add/remove files without re-compressing the whole archive. In the most commonly used zipping algorithm "DEFLATE", each file is first compressed by itself, and the results are then joined together. This means that some potential is lost in terms of finding patterns across multiple files, but it does allow for better flexibility, which matches the most common use case of zip files. So essentially when you add a new file, you just compress that single file by itself, and add that to the archive. This is in contrast to other other formats like .tar.gz, where all the files are first joined together (.tar), and then the result is gzipped together.

Source: https://en.wikipedia.org/wiki/Zip_(file_format)

Upvotes: 2

Related Questions