Skip to content

Commit

Permalink
Only use Python-isal for levels 1 and 2
Browse files Browse the repository at this point in the history
  • Loading branch information
rhpvorderman committed Jan 17, 2024
1 parent ce44be6 commit c6bba8e
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/xopen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,17 +1021,17 @@ def _open_gz( # noqa: C901
compresslevel = XOPEN_DEFAULT_GZIP_COMPRESSION

if threads != 0:
if igzip_threaded:
try:
return igzip_threaded.open( # type: ignore
filename,
mode,
compresslevel,
**text_mode_kwargs,
threads=1,
)
except ValueError: # Wrong compression level
pass
# igzip level 0 compresses, while zlib outputs data in uncompressed
# deflate format. igzip level 3 is similar in size to 1 and 2 and slower.
# Other libraries do a better job at these levels.
if igzip_threaded and (compresslevel in (1, 2) or "r" in mode):
return igzip_threaded.open( # type: ignore
filename,
mode,
compresslevel,
**text_mode_kwargs,
threads=1,
)
if gzip_ng_threaded and zlib_ng:
try:
return gzip_ng_threaded.open(
Expand Down Expand Up @@ -1099,12 +1099,8 @@ def _open_reproducible_gzip(filename, mode: str, compresslevel: int):
mtime=0,
)
gzip_file = None
if igzip is not None:
try:
gzip_file = igzip.IGzipFile(**kwargs, compresslevel=compresslevel)
except ValueError:
# Compression level not supported, move to built-in gzip.
pass
if igzip is not None and (compresslevel in (1, 2) or "r" in mode):
gzip_file = igzip.IGzipFile(**kwargs, compresslevel=compresslevel)
elif gzip_ng is not None:
# Compression level should be at least 2 for zlib-ng to prevent very big files.
gzip_file = gzip_ng.GzipNGFile(**kwargs, compresslevel=max(compresslevel, 2))
Expand Down

0 comments on commit c6bba8e

Please sign in to comment.