Python: Creating a streaming gzip'd file-like?

前端 未结 5 1498
面向向阳花
面向向阳花 2020-12-24 07:06

I\'m trying to figure out the best way to compress a stream with Python\'s zlib.

I\'ve got a file-like input stream (input, below) and an o

5条回答
  •  时光说笑
    2020-12-24 07:53

    Use the cStringIO (or StringIO) module in conjunction with zlib:

    >>> import zlib
    >>> from cStringIO import StringIO
    >>> s.write(zlib.compress("I'm a lumberjack"))
    >>> s.seek(0)
    >>> zlib.decompress(s.read())
    "I'm a lumberjack"
    

提交回复
热议问题