From 005efe9282434ab1beb767e1f63782520985e835 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Mon, 19 Feb 2024 08:53:17 +0100 Subject: [PATCH] Only throw compression level errors in write and append modes --- CHANGELOG.rst | 2 ++ src/isal/igzip.py | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 39bcbb53..7ba71854 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,8 @@ Changelog version 1.6.0-dev ----------------- ++ Fix a bug where compression levels for IGzipFile where checked, even when + in read mode. + Update statically linked ISA-L release to 2.31.0 + Fix an error that occurred in the ``__close__`` function when a threaded writer was initialized with incorrect parameters. diff --git a/src/isal/igzip.py b/src/isal/igzip.py index 5b942862..3c2ed2cb 100644 --- a/src/isal/igzip.py +++ b/src/isal/igzip.py @@ -151,11 +151,12 @@ def __init__(self, filename=None, mode=None, If omitted or None, the current time is used. """ if not (isal_zlib.ISAL_BEST_SPEED <= compresslevel - <= isal_zlib.ISAL_BEST_COMPRESSION): + <= isal_zlib.ISAL_BEST_COMPRESSION) and "r" not in mode: raise ValueError( - "Compression level should be between {0} and {1}.".format( - isal_zlib.ISAL_BEST_SPEED, isal_zlib.ISAL_BEST_COMPRESSION - )) + f"Compression level should be between " + f"{isal_zlib.ISAL_BEST_SPEED} and " + f"{isal_zlib.ISAL_BEST_COMPRESSION}, got {compresslevel}." + ) super().__init__(filename, mode, compresslevel, fileobj, mtime) if self.mode == WRITE: self.compress = isal_zlib.compressobj(compresslevel,