Unzip: Memory Error
mcl
mcl.office at googlemail.com
Wed Aug 29 14:58:59 EDT 2007
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.
I am running on a hosted Apache web server
I am using some code I found on the web somewhere.
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()
Error Traceback: Line 357 gives the Memory Error
I have removed paths from file references
==============================================
MemoryError Python 2.3.4: /usr/bin/python
Wed Aug 29 19:38:22 2007
A problem occurred in a Python script. Here is the sequence of
function calls leading up to the error, in the order they occurred.
/qlunzip.py
58
59
60 if __name__ == "__main__" :
61 unzipMain()
62
unzipMain = <function unzipMain>
/qlunzip.py in unzipMain()
53 destdir = getDestDir()
54 print destdir, gv.nl
55 unzip_file_into_dir(zips, destdir)
56
57
global unzip_file_into_dir = <function unzip_file_into_dir>, zips = '/
pcodes.zip', destdir = '/pcodes/'
/qlunzip.py in unzip_file_into_dir(file='pcodes.zip', dir='pcodes/')
34 else:
35 outfile = open(os.path.join(dir, name),
'wb')
36 outfile.write(zfobj.read(name))
37 outfile.close()
38
outfile = <open file 'pcodes/pcodes.lst', mode 'wb'>, outfile.write =
<built-in method write of file object>, zfobj = <zipfile.ZipFile
instance>, zfobj.read = <bound method ZipFile.read of <zipfile.ZipFile
instance>>, name = 'pcodes.lst'
/usr/lib/python2.3/zipfile.py in read(self=<zipfile.ZipFile
instance>, name='pcodes.lst')
355 # zlib compress/decompress code by Jeremy Hylton of
CNRI
356 dc = zlib.decompressobj(-15)
357 bytes = dc.decompress(bytes)
358 # need to feed in unused pad byte so that zlib won't
choke
359 ex = dc.decompress('Z') + dc.flush()
bytes = '\xc4\x9d]\x93\xab8\x92\x86\xef7b\xff\x83\xa3/\xf6f\xba
\xa7\xe7\xa2g#vwf6\x8a\x02\xc3\xd04\x8d\r\x1e\x7f\xdclP\xb6\xcav\x1c
\xca\xd4`\xfbx...; \xb7jp\x06V{\xaf\xc3\xa5\xa7;\xdd\xd2\xaaD\x7f)c
\xc6\x9d\x0f\xf2\xff-\xc9\x92\xc3\x1d\xa4`\xe0\xb8\x06)\x188\x9cA\n
\x06\x8e\x1bPc\xf8\xf0\x1f', dc = <zlib.Decompress object>,
dc.decompress = <built-in method decompress of zlib.Decompress object>
MemoryError:
args = ()
============================================================
Any help much appreciated
Richard
More information about the Python-list
mailing list