Reputation: 56242
I've found this snippet, which seems to do the job, but I can't understand why it uses StringIO. Isn't f
already a file-like object? What is the need to read it, then make it look like a file again, only to read it again? I've tested it (well, a slightly modified version of it), and it doesn't work without StringIO.
Upvotes: 3
Views: 3171
Reputation: 82924
It's possible that the gunzip code needs a file-like object that has a seek
method, which a HTTP library is very unlikely to provide. What does "doesn't work" mean? Error message?
If efficiency is your real concern, slightly modify the code so that it uses cStringIO, not StringIO.
Upvotes: 1
Reputation: 10917
Seems to be a flaw in python standard library which is fixed in Python 3.2.
see http://www.enricozini.org/2011/cazzeggio/python-gzip/
urllib
and urllib2
file objects do not provide a method tell()
as requested by gzip.
Upvotes: 1
Reputation: 3287
The way I read the relevant part of the code says:
read
method)Upvotes: 0