Skip to content

Commit

Permalink
Use igzip's threaded open
Browse files Browse the repository at this point in the history
  • Loading branch information
rhpvorderman committed Oct 7, 2023
1 parent b5a67ee commit 1a42390
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package_dir =
=src
packages = find:
install_requires =
isal>=1.0.0; platform.machine == "x86_64" or platform.machine == "AMD64" or platform.machine == "aarch64"
isal>=1.4.0; platform.machine == "x86_64" or platform.machine == "AMD64" or platform.machine == "aarch64"
typing_extensions; python_version<'3.8'

[options.packages.find]
Expand Down
22 changes: 12 additions & 10 deletions src/xopen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
isal_zlib: Optional[ModuleType]

try:
from isal import igzip, isal_zlib
from isal import igzip, igzip_threaded, isal_zlib
except ImportError:
igzip = None
isal_zlib = None
Expand Down Expand Up @@ -1022,8 +1022,6 @@ def _open_external_gzip_reader(
# No igzip installed or version does not support reading
# concatenated files.
pass
if igzip:
return PipedPythonIsalReader(filename, mode, **text_mode_kwargs)
try:
return PipedPigzReader(filename, mode, threads=threads, **text_mode_kwargs)
except OSError:
Expand All @@ -1039,13 +1037,6 @@ def _open_external_gzip_writer(
except (OSError, ValueError):
# No igzip installed or compression level higher than 3
pass
if igzip: # We can use the CLI from isal.igzip
try:
return PipedPythonIsalWriter(
filename, mode, compresslevel, **text_mode_kwargs
)
except ValueError: # Wrong compression level
pass
try:
return PipedPigzWriter(
filename, mode, compresslevel, threads=threads, **text_mode_kwargs
Expand All @@ -1056,6 +1047,17 @@ def _open_external_gzip_writer(

def _open_gz(filename, mode: str, compresslevel, threads, **text_mode_kwargs):
assert mode in ("rt", "rb", "wt", "wb", "at", "ab")
if igzip_threaded:
try:
igzip_threaded.open(
filename,
mode,
compresslevel or isal_zlib.ISAL_DEFAULT_COMPRESSION,
**text_mode_kwargs,
threads=threads or 1,
)
except ValueError: # Wrong compression level
pass
if threads != 0:
try:
if "r" in mode:
Expand Down

0 comments on commit 1a42390

Please sign in to comment.