This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add gzip function to read gzip'd strings
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: nadeem.vawda, rhettinger, serhiy.storchaka
Priority: normal Keywords:

Created on 2012-06-17 01:34 by rhettinger, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg163004 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2012-06-17 01:34
The API for the gzip module is convenient for reading gzipped file but is rather awkward for reading bytes downloaded from a socket:

  >>> import gzip, io
  >>> from urllib.request import urlopen, Request
  >>> u = urlopen(Request('http://www.nytimes.com', headers={'Accept-Encoding': 'gzip'}))
  >>> content = gzip.GzipFile(fileobj=io.BytesIO(u.read()), mode='rb').read()

It would be better if the last line could be written:

  >>> content = gzip.decompress_file(u)
msg163005 - (view) Author: Nadeem Vawda (nadeem.vawda) * (Python committer) Date: 2012-06-17 01:41
There is already such a function, gzip.decompress() - it was added in 3.2.
msg163030 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-06-17 08:24
Why not simple gzip.GzipFile(fileobj=u).read()?
msg163079 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2012-06-17 17:56
Thanks.  I didn't know that this had already been added to 3.2
History
Date User Action Args
2022-04-11 14:57:31adminsetgithub: 59292
2012-06-17 17:56:46rhettingersetmessages: + msg163079
2012-06-17 10:29:05pitrousetstatus: open -> closed
resolution: not a bug -> out of date
2012-06-17 08:24:38serhiy.storchakasetstatus: pending -> open
nosy: + serhiy.storchaka
messages: + msg163030

2012-06-17 01:41:51nadeem.vawdasetstatus: open -> pending

nosy: + nadeem.vawda
messages: + msg163005

resolution: not a bug
stage: resolved
2012-06-17 01:34:38rhettingercreate