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: gzip.compress incorrectly ignores level parameter
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: rhpvorderman
Priority: normal Keywords: patch

Created on 2022-01-05 11:14 by rhpvorderman, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 30416 open rhpvorderman, 2022-01-05 11:17
Messages (2)
msg409749 - (view) Author: Ruben Vorderman (rhpvorderman) * Date: 2022-01-05 11:14
def compress(data, compresslevel=_COMPRESS_LEVEL_BEST, *, mtime=None):
    """Compress data in one shot and return the compressed string.

    compresslevel sets the compression level in range of 0-9.
    mtime can be used to set the modification time. The modification time is
    set to the current time by default.
    """
    if mtime == 0:
        # Use zlib as it creates the header with 0 mtime by default.
        # This is faster and with less overhead.
        return zlib.compress(data, level=compresslevel, wbits=31)
    header = _create_simple_gzip_header(compresslevel, mtime)
    trailer = struct.pack("<LL", zlib.crc32(data), (len(data) & 0xffffffff))
    # Wbits=-15 creates a raw deflate block.
    return header + zlib.compress(data, wbits=-15) + trailer
                                       ^ 
                                       Level should be here

I noticed this while benchmarking against python-isal. This benchmarks add level 1 and it seemed oddly slow. 

This can be fixed easily. PR coming up.
msg414361 - (view) Author: Ruben Vorderman (rhpvorderman) * Date: 2022-03-02 14:33
ping
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90425
2022-03-02 14:33:46rhpvordermansetmessages: + msg414361
2022-01-05 11:17:48rhpvordermansetkeywords: + patch
stage: patch review
pull_requests: + pull_request28622
2022-01-05 11:14:04rhpvordermancreate