Zipfile content reading via an iterator?

Tim Chase python.list at tim.thechases.com
Tue Jan 29 08:06:12 EST 2008


>>> I'm dealing with several large items that have been zipped up to
>>> get quite impressive compression.  However, uncompressed, they're
>>> large enough to thrash my memory to swap and in general do bad
>>> performance-related things.  I'm trying to figure out how to
>>> produce a file-like iterator out of the contents of such an item.
>>
>> The Time Machine in action again - that's already done, but in SVN. You  
>> want the new ZipFile.open(filename) method, which returns a file-like  
>> object.
> 
> Thanks!  I'll give the 2.6 version a try.

Just to follow up on this, I dropped the the 2.6 version of
zipfile.py in my project folder (where the machine is currently
running Python2.4), used the ZipFile.open() and it worked fine.
I was able to successfully extract a 960 meg MDB file from the
zip-file.  The one thing that did throw me off is that it
rejected specifying that the file be opened as binary:

  z = ZipFile('foo.zip')
  f = z.open('path/to/file.mdb', 'rb') #failed
  f = z.open('path/to/file.mdb') # worked

but just opening with no type specification did allow me to
extract the file successfully.  I don't know if I just struck it
lucky with newline/EOF translations, or if it really does do
binary file handling and you don't get a choice of non-binary
file handling.

Anyways, thanks to Gabriel (and all the authors of Python
zipfile.py library) for the solution.

-tkc




More information about the Python-list mailing list