Python decompressing gzip chunk-by-chunk

后端 未结 2 1878
粉色の甜心
粉色の甜心 2020-11-29 04:42

I\'ve a memory- and disk-limited environment where I need to decompress the contents of a gzip file sent to me in string-based chunks (over xmlrpc binary transfer). However,

相关标签:
2条回答
  • 2020-11-29 05:02

    I've got a more detailed answer here: https://stackoverflow.com/a/22310760/1733117

    d = zlib.decompressobj(zlib.MAX_WBITS|32)
    

    per documentation this automatically detects the header (zlib or gzip).

    0 讨论(0)
  • 2020-11-29 05:14

    gzip and zlib use slightly different headers.

    See How can I decompress a gzip stream with zlib?

    Try d = zlib.decompressobj(16+zlib.MAX_WBITS).

    And you might try changing your chunk size to a power of 2 (say CHUNKSIZE=1024) for possible performance reasons.

    0 讨论(0)
提交回复
热议问题