Skip to content

Commit

Permalink
Merge pull request #180 from pycompression/release_1.5.3
Browse files Browse the repository at this point in the history
Release 1.5.3
  • Loading branch information
rhpvorderman authored Nov 24, 2023
2 parents b4d1be1 + 756f097 commit f380197
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def build_isa_l():

setup(
name="isal",
version="1.5.2",
version="1.5.3",
description="Faster zlib and gzip compatible compression and "
"decompression by providing python bindings for the ISA-L "
"library.",
Expand All @@ -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'},
Expand Down
2 changes: 1 addition & 1 deletion src/isal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
"__version__"
]

__version__ = "1.5.2"
__version__ = "1.5.3"
8 changes: 7 additions & 1 deletion src/isal/igzip_threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
22 changes: 22 additions & 0 deletions tests/test_igzip_threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit f380197

Please sign in to comment.