RIght now, reading a file from a ZipFile loads the
whole file into memory and returns it as a string. This
makes the module useless for large files.
My patch allows you to get a file-like object for each
entry in the zip, so you can do:
f = z.readfile("largfile")
print f.read(500)
Instead of the current method:
s = z.read("largefile")
print s[:500]
Much nicer if "largefile" is a 10MB file...
I added a function ZipFile.readfile, two classes for
the file-like objects (uncompressed and deflated), and
reimplemented ZipFile.read to use ZipFile.readfile. I
also added a small test to test_zipfile.py, although
some more extensive testing would be better, as usual.
I will be using this code in a project, which'll
provide additional testing.
|