Add file to zip, or replace file in zip

Edward Elliott nobody at 127.0.0.1
Sun Apr 30 16:33:20 EDT 2006


Scott David Daniels wrote:
> It is not currently possible to delete or replace individual elements
> in a zip file, nor (in all likelihood) would you want to do so.  It
> would require having the zip[ file in a broken state for some time
> as you copy data from one area of the zip to another.  

If zips just used sequential access like tar files, you could append newer
versions without a problem.  You windows kids and your crazy data formats.

> Any error 
> (or raised exception like Control-C) during this process is likely
> to leave you with an inconsistent and therefore unreadable zip file.

Isn't that true of any modifications to the zip archive, e.g. appending a
new file rather than replacing an existing one?

> in one pass, copy all non-deleted files to a new zip (which you can then
> swap for the original zip).  Shortcutting this process puts all data in
> your zip file at risk.

Again, isn't this true of any substantive change to any file whatsoever?  
Errors during write can always leave your data in an inconsistent state,
unless your data uses a structured append format like journaled
filesystems.  That seems like an orthogonal issue to replacing a file in
the archive.




More information about the Python-list mailing list