[Python-Dev] zipfile.py
M.-A. Lemburg
mal@lemburg.com
Thu, 16 Dec 1999 22:23:30 +0100
"James C. Ahlstrom" wrote:
>
> "James C. Ahlstrom" wrote:
>
> > ftp://ftp.interet.com/pub/pylib.html
>
> I just changed zipfile.py so that regular zip compression
> works. And if zlib is available,
> its crc32() is used instead of the Python version.
>
> I should mention that the current code rejects zip files which have
> an archive comment added to the end. Accepting them would require
> a search, and I am not sure it is worth it.
I don't think it is needed for our purposes, but maybe a
subclass could provide it ?
FYI, I've tested the module against mxStack-0.3.0.zip which
you can find on my Python Pages. It was created using Info-ZIP's
zip 2.2 on Linux.
Unfortunately, I always get the following traceback when trying
to print the directory:
>>> z.open('../projects/distribution/mxStack-0.3.0.zip','rb')
>>> z.dir()
File Name Modified Size
Stack/mxStack/mxStack.h 1999-04-16 10:50:06 4368
Stack/mxStack/mxstdlib.h 1999-04-13 15:37:52 5433
Traceback (innermost last):
File "<stdin>", line 1, in ?
File "/home/lemburg/lib/zipfile.py", line 120, in dir
bytes = self.read(name) # Just to check CRC-32
File "/home/lemburg/lib/zipfile.py", line 133, in read
bytes = zlib.decompress(bytes, -15)
zlib.error: Error -5 while decompressing data
Some notes on the API:
----------------------
* I would find it more convenient if the filename and mode
would be constructor parameters, e.g.
zfile = zipfile('myfile.zip','rb')
with compression defaulting to 8 rather than 0 (most zip files
will be deflated since this is the ZIP default).
* Also, I would like a method much like the os.listdir()
which returns a list of filenames rather than print it
to stdout.
* .is_zipfile() should probably be a separate function: it
doesn't use any of the class' features.
More wishes to come ;-)
So far: Great Work !
Aside: I found that you are using undocumented arguments to
zlib.compressobj() ... are these extra arguments left out of
the documentation on purpose or by simple oversight ? I couldn't
find them in the HTML docs and neither in the docstrings.
--
Marc-Andre Lemburg
______________________________________________________________________
Y2000: 15 days left
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/