Read and write gzip header and trailer with zlib


RHEL, SLES and Ubuntu for IBM zSystems (aka s390x) ship with a zlib
optimization [1] that significantly improves deflate and inflate
performance on this platform by using a specialized CPU instruction.

This instruction not only compresses the data, but also computes a
checksum. At the moment Pyhton’s gzip support performs compression and
checksum calculation separately, which creates unnecessary overhead on

The reason is that Python needs to write specific values into gzip
header; and when this support was introduced in year 1997, there was
indeed no better way to do this.

Since v1.2.2.1 (2011) zlib provides inflateGetHeader() and
deflateSetHeader() functions for that, so Python does not have to deal
with the exact header and trailer format anymore.

I would like to contribute a patch that replaces manual creation
of gzip headers and trailers with these functions [2].

Please let me know what you think.

Best regards,

[2] gh-??????: Read and write gzip header and trailer with zlib · iii-i/cpython@810dac9 · GitHub

1 Like

Such a patch makes sense to me.