Re: trying to gzip uncompress a StringIO
- From: John Machin <sjmachin@xxxxxxxxxxx>
- Date: Wed, 23 May 2007 08:26:09 +1000
On 23/05/2007 7:48 AM, Gabriel Genellina wrote:
En Tue, 22 May 2007 14:22:25 -0300, <bob@xxxxxxxx> escribió:
I'm using the code below to read the zipped, base64 encoded WMF file
saved in an XML file with "Save as XML" from MS Word. As the "At this
point" comment shows, I know that the base64 decoding is going fine,
but unzipping from the decodedVersion StringIO object isn't getting me
anything, because the len(fileContent) call is returning 0. Any
suggestions?
Perhaps GzipFile reads from the current position till end (and sees nothing).
Try rewinding the file:
decodedVersion = StringIO.StringIO()decodedVersion.seek(0)
base64.decode(open(infile, 'r'),decodedVersion)
fileObj = gzip.GzipFile(fileobj=decodedVersion);
fileContent = fileObj.read()
print len(fileContent)
>>> import StringIO
>>> s = StringIO.StringIO()
>>> s.write('blahblah\n')
>>> s.read()
''
>>> s.seek(0)
>>> s.read()
'blahblah\n'
>>>
The error would have been screamingly obvious on an open-reel mag. tape drive :-)
I suggest that "perhaps" and "try" are a little too tentative :-) GzipFile (or anything else that reads a file) is entitled to assume that the file(-like) object it is given has had its read head positioned by the caller at wherever the caller wants it to read from. Callers are entitled to assume that the reader will not arbitrarily rewind (or skip backwards/forwards to tape mark!) before reading.
Cheers,
John
.
- Follow-Ups:
- Re: trying to gzip uncompress a StringIO
- From: bob
- Re: trying to gzip uncompress a StringIO
- From: bob
- Re: trying to gzip uncompress a StringIO
- From: bob
- Re: trying to gzip uncompress a StringIO
- From: bob
- Re: trying to gzip uncompress a StringIO
- References:
- trying to gzip uncompress a StringIO
- From: bob
- Re: trying to gzip uncompress a StringIO
- From: Gabriel Genellina
- trying to gzip uncompress a StringIO
- Prev by Date: Re: 'int' object is not callable in an threaded app
- Next by Date: Re: trying to gzip uncompress a StringIO
- Previous by thread: Re: trying to gzip uncompress a StringIO
- Next by thread: Re: trying to gzip uncompress a StringIO
- Index(es):
Relevant Pages
|