[Python-Dev] Problems with zipfile.py
James C. Ahlstrom
jim@interet.com
Sun, 08 Apr 2001 09:50:23 -0400
The zipfile module seems to have been well received, and
I have the impression that many people are using it. But
I have been getting complaints that it won't read ZIP files
created by InfoZip. At first I thought this was a problem
with incompatible zlib compression versions, but now I have
found the problem.
It turns out that InfoZip's Wiz version 5.02 (and maybe other
InfoZip versions) creates ZIP files with an incorrect value
for "extra data length" in the central directory, but the correct
value in the file header. The "extra data" is before the compressed
file data, and so this causes the file data offset to be off slightly
thus causing complaints from the zlib decompressor. I changed
zipfile.py to use the file header value, and it fixes the problem.
I also added a new method restore(self, name, fileobject) which
was suggested some time ago by MAL. It writes to an open file
or any other object with a write() method. It avoids the need
to read the whole file into memory.
I also changed the "raise" statements to use the "zipfile.error"
exception. This agrees with the documentation, but previously
zipfile raised a variety of exceptions. This also fixes the
complaint that "BadZipfile" should be spelled "BadZipFile".
The new changed zipfile.py is available from
ftp://ftp.interet.com/pub/zipfile.py
and is currently being tested by a user. Please take a look.
JimA