[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Windows gzip problem

John Earls

2/28/2008 11:10:00 PM

Hello,

I am having a problem with gzip. The code worked fine under linux but
when I moved it over to windows it is getting stuck unzipping a gz
file.

-- snippet --

fileObj = gzip.GzipFile(iceGetter.file.localFileName, 'rb')
uncompressedFileName = iceGetter.file.localFileName[:-3]
output = open(uncompressedFileName, 'wb')
output.write(fileObj.read())
output.close()
fileObj.close()

-- snippet --

typing "python autoIce.py" gets this error:
--error--
Traceback(most recent call last):
File "runAuto.py", line 17 in ?
output.write(fileObj.read())
File "C:\Python24\lib\gzip.py". line 217 in read
self._read(readsize)
File "C:\Python24\lib\gzip.py", line 276 in _read
uncompress.decompress.decompress(buf)
Memory Error

--end error--
I tried playing around with the wb/rb when writing and unzipping, like
this post [http://groups.google.com/group/comp.la...
browse_thread/thread/96651e3cd2dc6070/e94ae3b22fc78a1b?lnk=gst&q=gzip
+windows#e94ae3b22fc78a1b] suggested and that did not seem to change
anything.

I would really appreciate any assistance on this.

Thanks

John
2 Answers

Gabriel Genellina

2/29/2008 12:58:00 AM

0

En Thu, 28 Feb 2008 21:09:30 -0200, John Earls <yt.rabb@gmail.com>
escribió:

> I am having a problem with gzip. The code worked fine under linux but
> when I moved it over to windows it is getting stuck unzipping a gz
> file.
>
> -- snippet --
>
> fileObj = gzip.GzipFile(iceGetter.file.localFileName, 'rb')
> uncompressedFileName = iceGetter.file.localFileName[:-3]
> output = open(uncompressedFileName, 'wb')
> output.write(fileObj.read())
> output.close()
> fileObj.close()
>
> -- snippet --
>
> typing "python autoIce.py" gets this error:
> --error--
> Traceback(most recent call last):
> File "runAuto.py", line 17 in ?
> output.write(fileObj.read())
> File "C:\Python24\lib\gzip.py". line 217 in read
> self._read(readsize)
> File "C:\Python24\lib\gzip.py", line 276 in _read
> uncompress.decompress.decompress(buf)
> Memory Error

Is the uncompressed file big? Instead of output.write(fileObj.read())
--that reads the whole contents in memory-- try
shutil.copyfileobj(fileObj, output)

--
Gabriel Genellina

John Earls

2/29/2008 3:45:00 AM

0

On Feb 28, 6:57 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
> En Thu, 28 Feb 2008 21:09:30 -0200, John Earls <yt.r...@gmail.com>
> escribió:
>
>
>
> > I am having a problem with gzip. The code worked fine under linux but
> > when I moved it over to windows it is getting stuck unzipping a gz
> > file.
>
> > -- snippet --
>
> > fileObj = gzip.GzipFile(iceGetter.file.localFileName, 'rb')
> > uncompressedFileName = iceGetter.file.localFileName[:-3]
> > output = open(uncompressedFileName, 'wb')
> > output.write(fileObj.read())
> > output.close()
> > fileObj.close()
>
> > -- snippet --
>
> > typing "python autoIce.py" gets this error:
> > --error--
> > Traceback(most recent call last):
> > File "runAuto.py", line 17 in ?
> > output.write(fileObj.read())
> > File "C:\Python24\lib\gzip.py". line 217 in read
> > self._read(readsize)
> > File "C:\Python24\lib\gzip.py", line 276 in _read
> > uncompress.decompress.decompress(buf)
> > Memory Error
>
> Is the uncompressed file big? Instead of output.write(fileObj.read())
> --that reads the whole contents in memory-- try
> shutil.copyfileobj(fileObj, output)
>
> --
> Gabriel Genellina

That worked perfectly.

Thank you so much.