On Fri, Aug 1, 2008 at 7:32 PM, Oleg Broytmann <[EMAIL PROTECTED]> wrote: > On Fri, Aug 01, 2008 at 07:27:38PM +0530, Anand Balachandran Pillai wrote: >> Of these, I have a gripe with gzip - it does not provide a simple >> way of compressing/uncompressing a string > > It does. It is zlib.compress() and zlib.decompress().
Yes, I know gzip uses zlib for performing compression. But zlib.compress does not return a string which can be de-compressed using gzip directly, because the gzip headers are missing. >>> import gzip >>> import zlib >>> s='This is a line of text' >>> sc=zlib.compress(s) >>> g=gzip.GzipFile(fileobj=cStringIO.StringIO(sc)) >>> print g.read() Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/gzip.py", line 218, in read self._read(readsize) File "/usr/lib/python2.4/gzip.py", line 261, in _read self._read_gzip_header() File "/usr/lib/python2.4/gzip.py", line 162, in _read_gzip_header raise IOError, 'Not a gzipped file' IOError: Not a gzipped file I think being able to send gzip compressed strings directly would be useful for applications which require to send gzip data over the wire without having to write to files and read-back. > > Oleg. > -- > Oleg Broytmann http://phd.pp.ru/ [EMAIL PROTECTED] > Programmers don't die, they just GOSUB without RETURN. > _______________________________________________ > Python-3000 mailing list > Python-3000@python.org > http://mail.python.org/mailman/listinfo/python-3000 > Unsubscribe: > http://mail.python.org/mailman/options/python-3000/abpillai%40gmail.com > -- -Anand _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com