Skip to content

Commit f380197

Browse files
authored
Merge pull request #180 from pycompression/release_1.5.3
Release 1.5.3
2 parents b4d1be1 + 756f097 commit f380197

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ Changelog
77
.. This document is user facing. Please word the changes in such a way
88
.. that users understand how the changes affect the new version.
99
10+
version 1.5.3
11+
-----------------
12+
+ Fix a bug where append mode would not work when using
13+
``igzip_threaded.open``.
14+
1015
version 1.5.2
1116
-----------------
1217
+ Fix a bug where a filehandle remained opened when ``igzip_threaded.open``

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def build_isa_l():
135135

136136
setup(
137137
name="isal",
138-
version="1.5.2",
138+
version="1.5.3",
139139
description="Faster zlib and gzip compatible compression and "
140140
"decompression by providing python bindings for the ISA-L "
141141
"library.",
@@ -145,7 +145,7 @@ def build_isa_l():
145145
long_description_content_type="text/x-rst",
146146
cmdclass={"build_ext": BuildIsalExt},
147147
license="PSF-2.0",
148-
keywords="isal isa-l compression deflate gzip igzip",
148+
keywords="isal isa-l compression deflate gzip igzip threads",
149149
zip_safe=False,
150150
packages=find_packages('src'),
151151
package_dir={'': 'src'},

src/isal/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
"__version__"
2828
]
2929

30-
__version__ = "1.5.2"
30+
__version__ = "1.5.3"

src/isal/igzip_threaded.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def open(filename, mode="rb", compresslevel=igzip._COMPRESS_LEVEL_TRADEOFF,
6363
gzip_file = io.BufferedWriter(
6464
_ThreadedGzipWriter(
6565
filename,
66+
mode.replace("t", "b"),
6667
block_size=block_size,
6768
level=compresslevel,
6869
threads=threads
@@ -197,11 +198,16 @@ class _ThreadedGzipWriter(io.RawIOBase):
197198
"""
198199
def __init__(self,
199200
filename,
201+
mode: str = "wb",
200202
level: int = isal_zlib.ISAL_DEFAULT_COMPRESSION,
201203
threads: int = 1,
202204
queue_size: int = 1,
203205
block_size: int = 1024 * 1024,
204206
):
207+
if "t" in mode or "r" in mode:
208+
raise ValueError("Only binary writing is supported")
209+
if "b" not in mode:
210+
mode += "b"
205211
self.lock = threading.Lock()
206212
self.exception: Optional[Exception] = None
207213
self.level = level
@@ -238,7 +244,7 @@ def __init__(self,
238244
self.running = False
239245
self._size = 0
240246
self._closed = False
241-
self.raw = open_as_binary_stream(filename, "wb")
247+
self.raw = open_as_binary_stream(filename, mode)
242248
self._write_gzip_header()
243249
self.start()
244250

tests/test_igzip_threaded.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,25 @@ def test_writer_write_after_close(threads):
169169
with pytest.raises(ValueError) as error:
170170
f.write(b"abc")
171171
error.match("closed")
172+
173+
174+
def test_igzip_threaded_append(tmp_path):
175+
test_file = tmp_path / "test.txt.gz"
176+
with igzip_threaded.open(test_file, "wb") as f:
177+
f.write(b"AB")
178+
with igzip_threaded.open(test_file, mode="ab") as f:
179+
f.write(b"CD")
180+
with gzip.open(test_file, "rb") as f:
181+
contents = f.read()
182+
assert contents == b"ABCD"
183+
184+
185+
def test_igzip_threaded_append_text_mode(tmp_path):
186+
test_file = tmp_path / "test.txt.gz"
187+
with igzip_threaded.open(test_file, "wt") as f:
188+
f.write("AB")
189+
with igzip_threaded.open(test_file, mode="at") as f:
190+
f.write("CD")
191+
with gzip.open(test_file, "rt") as f:
192+
contents = f.read()
193+
assert contents == "ABCD"

0 commit comments

Comments
 (0)