Unzip: Memory Error

David Bolen db3l.net at gmail.com
Wed Aug 29 16:18:30 EDT 2007


mcl <mcl.office at googlemail.com> writes:

> I am trying to unzip an 18mb zip containing just a single 200mb file
> and I get a Memory Error.  When I run the code on a smaller file 1mb
> zip, 11mb file, it works fine.
(...)
> def unzip_file_into_dir(file, dir):
> 	#os.mkdir(dir, 0777)
> 	zfobj = zipfile.ZipFile(file)
> 	for name in zfobj.namelist():
> 		if name.endswith('/'):
> 			os.mkdir(os.path.join(dir, name))
> 		else:
> 			outfile = open(os.path.join(dir, name), 'wb')
> 			outfile.write(zfobj.read(name))
> 			outfile.close()

The "zfobj.read(name)" call is reading the entire file out of the zip
into a string in memory.  It sounds like it's exceeding the resources
you have available (whether overall or because the Apache runtime
environment has stricter limits).

You may want to peek at a recent message from me in the "Unable to
read large files from zip" thread, as the suggestion there may also be
suitable for your purposes.

http://groups.google.com/group/comp.lang.python/msg/de04105c170fc805?dmode=source
-- David



More information about the Python-list mailing list