Add file to zip, or replace file in zip

Scott David Daniels scott.daniels at acm.org
Mon May 1 13:48:01 EDT 2006


Edward Elliott wrote:
> Scott David Daniels wrote:
>>...
 > ... You windows kids and your crazy data formats.
There were a few oth OS's than Linux and Windows.  Maybe you
should call me "you crazy Tenex kid."  Knuth says, "the fastest
way to search is to know where to go." -- Zips have locations of
files, and you needn't read in a lot of a huge zip to find and
extract a couple of files.

>> 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?

Nope.  There is enough info in the zip to rebuild the directory
with a forward scan of the zip.  (Each entry has a file descr).
"appending" is really replacing backing up before the zip archive
directory and writing another entry, followed by a new directory.

>> 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.

--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list