classification
Title: GzipFile cannot be used for streaming
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 2.6, Python 2.5
process
Status: closed Resolution: duplicate
Dependencies: Superseder: gzip.GzipFile to accept stream as fileobj.
View: 914340
Assigned To: Nosy List: enrico, nadeem.vawda, ned.deily, stutzbach, ysj.ray
Priority: normal Keywords:

Created on 2011-03-19 16:18 by enrico, last changed 2011-03-20 21:28 by ned.deily. This issue is now closed.

Messages (3)
msg131427 - (view) Author: Enrico Zini (enrico) Date: 2011-03-19 16:18
Hello,

this snippet does not work, because GzipFile wants a file-like object that can do tell() and seek():

#!/usr/bin/python

import gzip
from urllib import urlopen

zfd = urlopen("http://ftp.debian.org/debian/dists/sid/Contents-udeb.gz")
fd = gzip.GzipFile(fileobj=zfd, mode="r")
for line in fd:
    foobar(line)

It must be possible to build a decompressing file-like object wrapper that can do without seeking, since it is obviously not a limitation of gzip decompression libraries. It would be extremely useful to have such a thing, as shown in the example snippet above.

Some more details (including a very annoying misrepresentation of the issue found in Dive Into Python) can be found at http://www.enricozini.org/2011/cazzeggio/python-gzip/ (I apologise about the ranting tone of the post).
msg131482 - (view) Author: ysj.ray (ysj.ray) Date: 2011-03-20 09:49
Looks like a duplicate issue of #9664 and #914340. And has been fixed in patch of #914340.
msg131545 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-03-20 21:28
As Ray points out, this feature is now available in Python 3.2. It was not backported to Python 2.7 as only bug fixes are now being accepted for Python 2.x, not new features.
History
Date User Action Args
2011-03-20 21:28:29ned.deilysetstatus: open -> closed

superseder: gzip.GzipFile to accept stream as fileobj.

nosy: + ned.deily
messages: + msg131545
resolution: duplicate
stage: resolved
2011-03-20 09:49:46ysj.raysetnosy: + ysj.ray
messages: + msg131482
2011-03-20 07:12:21nadeem.vawdasetnosy: + nadeem.vawda
2011-03-19 19:32:14stutzbachsetnosy: + stutzbach
2011-03-19 16:18:48enricocreate