Skip to content

Commit be6bdc7

Browse files
committed
Only throw compression level errors in write and append modes
1 parent 9b2556a commit be6bdc7

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Changelog
99
1010
version 1.6.0-dev
1111
-----------------
12+
+ Fix a bug where compression levels for IGzipFile where checked in read mode.
1213
+ Update statically linked ISA-L release to 2.31.0
1314
+ Fix an error that occurred in the ``__close__`` function when a threaded
1415
writer was initialized with incorrect parameters.

src/isal/igzip.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,12 @@ def __init__(self, filename=None, mode=None,
151151
If omitted or None, the current time is used.
152152
"""
153153
if not (isal_zlib.ISAL_BEST_SPEED <= compresslevel
154-
<= isal_zlib.ISAL_BEST_COMPRESSION):
154+
<= isal_zlib.ISAL_BEST_COMPRESSION) and "r" not in mode:
155155
raise ValueError(
156-
"Compression level should be between {0} and {1}.".format(
157-
isal_zlib.ISAL_BEST_SPEED, isal_zlib.ISAL_BEST_COMPRESSION
158-
))
156+
f"Compression level should be between "
157+
f"{isal_zlib.ISAL_BEST_SPEED} and "
158+
f"{isal_zlib.ISAL_BEST_COMPRESSION}, got {compresslevel}."
159+
)
159160
super().__init__(filename, mode, compresslevel, fileobj, mtime)
160161
if self.mode == WRITE:
161162
self.compress = isal_zlib.compressobj(compresslevel,

0 commit comments

Comments
 (0)