Skip to content

Commit

Permalink
Only throw compression level errors in write and append modes
Browse files Browse the repository at this point in the history
  • Loading branch information
rhpvorderman committed Feb 19, 2024
1 parent 9b2556a commit 577ca6b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/isal/igzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 577ca6b

Please sign in to comment.