From 60470b9273f41dc6a50f29c18c19669fed7baf49 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Fri, 3 Nov 2023 16:43:59 +0100 Subject: [PATCH 1/3] Set new version --- setup.py | 2 +- src/isal/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 22c16742..1cb13991 100644 --- a/setup.py +++ b/setup.py @@ -135,7 +135,7 @@ def build_isa_l(): setup( name="isal", - version="1.5.2", + version="1.6.0-dev", description="Faster zlib and gzip compatible compression and " "decompression by providing python bindings for the ISA-L " "library.", diff --git a/src/isal/__init__.py b/src/isal/__init__.py index 8a39a81a..f7257098 100644 --- a/src/isal/__init__.py +++ b/src/isal/__init__.py @@ -27,4 +27,4 @@ "__version__" ] -__version__ = "1.5.2" +__version__ = "1.6.0-dev" From e55dddd92fa9c2dcd7b021181fb7a73552b88f79 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Fri, 24 Nov 2023 09:16:12 +0100 Subject: [PATCH 2/3] Fix append mode bug --- CHANGELOG.rst | 5 +++++ src/isal/igzip_threaded.py | 8 +++++++- tests/test_igzip_threaded.py | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3e936f62..de602380 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,11 @@ Changelog .. This document is user facing. Please word the changes in such a way .. that users understand how the changes affect the new version. +version 1.5.3 +----------------- ++ Fix a bug where append mode would not work when using + ``igzip_threaded.open``. + version 1.5.2 ----------------- + Fix a bug where a filehandle remained opened when ``igzip_threaded.open`` diff --git a/src/isal/igzip_threaded.py b/src/isal/igzip_threaded.py index dd34e704..99eafc17 100644 --- a/src/isal/igzip_threaded.py +++ b/src/isal/igzip_threaded.py @@ -63,6 +63,7 @@ def open(filename, mode="rb", compresslevel=igzip._COMPRESS_LEVEL_TRADEOFF, gzip_file = io.BufferedWriter( _ThreadedGzipWriter( filename, + mode.replace("t", "b"), block_size=block_size, level=compresslevel, threads=threads @@ -197,11 +198,16 @@ class _ThreadedGzipWriter(io.RawIOBase): """ def __init__(self, filename, + mode: str = "wb", level: int = isal_zlib.ISAL_DEFAULT_COMPRESSION, threads: int = 1, queue_size: int = 1, block_size: int = 1024 * 1024, ): + if "t" in mode or "r" in mode: + raise ValueError("Only binary writing is supported") + if "b" not in mode: + mode += "b" self.lock = threading.Lock() self.exception: Optional[Exception] = None self.level = level @@ -238,7 +244,7 @@ def __init__(self, self.running = False self._size = 0 self._closed = False - self.raw = open_as_binary_stream(filename, "wb") + self.raw = open_as_binary_stream(filename, mode) self._write_gzip_header() self.start() diff --git a/tests/test_igzip_threaded.py b/tests/test_igzip_threaded.py index be6c3ca4..dbee85f8 100644 --- a/tests/test_igzip_threaded.py +++ b/tests/test_igzip_threaded.py @@ -169,3 +169,25 @@ def test_writer_write_after_close(threads): with pytest.raises(ValueError) as error: f.write(b"abc") error.match("closed") + + +def test_igzip_threaded_append(tmp_path): + test_file = tmp_path / "test.txt.gz" + with igzip_threaded.open(test_file, "wb") as f: + f.write(b"AB") + with igzip_threaded.open(test_file, mode="ab") as f: + f.write(b"CD") + with gzip.open(test_file, "rb") as f: + contents = f.read() + assert contents == b"ABCD" + + +def test_igzip_threaded_append_text_mode(tmp_path): + test_file = tmp_path / "test.txt.gz" + with igzip_threaded.open(test_file, "wt") as f: + f.write("AB") + with igzip_threaded.open(test_file, mode="at") as f: + f.write("CD") + with gzip.open(test_file, "rt") as f: + contents = f.read() + assert contents == "ABCD" From 756f0978844dd02daebf95f21e9584eb84d8df70 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Fri, 24 Nov 2023 09:27:47 +0100 Subject: [PATCH 3/3] Update version number, add threads keyword --- setup.py | 4 ++-- src/isal/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 1cb13991..7d422418 100644 --- a/setup.py +++ b/setup.py @@ -135,7 +135,7 @@ def build_isa_l(): setup( name="isal", - version="1.6.0-dev", + version="1.5.3", description="Faster zlib and gzip compatible compression and " "decompression by providing python bindings for the ISA-L " "library.", @@ -145,7 +145,7 @@ def build_isa_l(): long_description_content_type="text/x-rst", cmdclass={"build_ext": BuildIsalExt}, license="PSF-2.0", - keywords="isal isa-l compression deflate gzip igzip", + keywords="isal isa-l compression deflate gzip igzip threads", zip_safe=False, packages=find_packages('src'), package_dir={'': 'src'}, diff --git a/src/isal/__init__.py b/src/isal/__init__.py index f7257098..36c2a468 100644 --- a/src/isal/__init__.py +++ b/src/isal/__init__.py @@ -27,4 +27,4 @@ "__version__" ] -__version__ = "1.6.0-dev" +__version__ = "1.5.3"