[Python-Dev] zipfile.py and InfoZIP files
Mon, 06 Nov 2000 15:00:33 +0100
"James C. Ahlstrom" wrote:
> "M.-A. Lemburg" wrote:
> I am happy to modify zipfile.py as desired by this group.
> > I'm having trouble opening ZIP files created using InfoZIP's
> > zip utility (which uses zlib) with zipfile.py:
> > >>> x = z.read('README')
> > Traceback (innermost last):
> > File "<stdin>", line 1, in ?
> > File "/home/lemburg/lib/zipfile.py", line 242, in read
> > bytes = dc.decompress(bytes)
> > zlib.error: Error -3 while decompressing: incomplete dynamic bit lengths tree
> > Is this due to the installed zlib on my system being incompatible,
> > or is this a bug in zipfile.py ? I have libz version 1.1.3 and
> > zip version 2.2.
> I "borrowed" the zlib code from someone else, and it uses
> undocumented features. Since WinZip seems happy with the compression
> I left it alone. I wouldn't be surprised if other utilities have
> problems, especially if they use zlib. I am not sure what to
> do about this. My starting view is that there is only one
> compression method, and if WinZip accepts it, then InfoZip
> is wrong. Is there perhaps a version difference in zlib
> in Python vs InfoZip?
> Could you send me an InfoZip zip file?
As it turned out it was a false alarm: Python must have picked
up an old zlibmodule.so from somewhere which caused the
problem. A clean rebuild made zipfile work with my InfoZIP
files (all my Python Pages ZIP-archives are built using InfoZIP 2.2).
Now I get this error after working in interactive Python
mode with zipfile:
"ZipFile instance has no attribute 'fp'" in <method ZipFile.__del__ of ZipFile instance at 0x824524c> ignored
I guess the __del__ method has to be a bit more careful about
what it expects to find... sometimes the builtins may have
already been garbage collected.
> > Also, I wonder why zipfile forces the mode flag to be 'r',
> > 'w' and 'a' -- wouldn't it make more sense to only add 'b', etc.
> > to the mode flag instead ?!
> The 'b' is not necessary, as it is always added by zipfile.py
> when the file is opened. The [rwa] each do something
> different, and aren't really the same as a file open. I
> am not sure what you mean here.
Sorry, I was only reading the code and got the impression that
mode testing was done on the complete string you pass to the
constructor ... I missed the line "key = mode".
> > The ZipFile is also missing some kind of method which
> > extracts files in the ZIP archive to a file-like object. This
> > would be very useful for extracting large files from a ZIP
> > archive without having to first read in the whole file into
> > memory.
> The "read(self, name)" method returns the bytes, which you can
> write to a file if you want. What new method would you like?
I would like a method .copy(self, name, output) which
reads the file name from the ZIP archive and writes it directly to
the file-like object output. This should copy the file in chunks
of say 64kB in order to reduce memory load.
Python Pages: http://www.lemburg.com/python/