[New-bugs-announce] [issue46267] gzip.compress incorrectly ignores level parameter
Ruben Vorderman
report at bugs.python.org
Wed Jan 5 06:14:04 EST 2022
New submission from Ruben Vorderman <r.h.p.vorderman at lumc.nl>:
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.
----------
components: Library (Lib)
messages: 409749
nosy: rhpvorderman
priority: normal
severity: normal
status: open
title: gzip.compress incorrectly ignores level parameter
type: behavior
versions: Python 3.11
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46267>
_______________________________________
More information about the New-bugs-announce
mailing list