|
12 | 12 | import subprocess |
13 | 13 | import sys |
14 | 14 | import tempfile |
| 15 | +import zlib |
15 | 16 | from pathlib import Path |
16 | 17 |
|
17 | 18 | from isal import igzip_threaded |
@@ -243,15 +244,28 @@ def test_threaded_program_can_exit_on_error(tmp_path, mode, threads): |
243 | 244 |
|
244 | 245 | @pytest.mark.parametrize("threads", [1, 2]) |
245 | 246 | def test_flush(tmp_path, threads): |
| 247 | + empty_block_end = b"\x00\x00\xff\xff" |
| 248 | + deflate_last_block = zlib.compress(b"", wbits=-15) |
246 | 249 | test_file = tmp_path / "output.gz" |
247 | 250 | with igzip_threaded.open(test_file, "wb", threads=threads) as f: |
248 | 251 | f.write(b"1") |
249 | 252 | f.flush() |
250 | | - assert gzip.decompress(test_file.read_bytes()) == b"1" |
| 253 | + data = test_file.read_bytes() |
| 254 | + assert data[-4:] == empty_block_end |
| 255 | + # Cut off gzip header and end data with an explicit last block to |
| 256 | + # test if the data was compressed correctly. |
| 257 | + deflate_block = data[10:] + deflate_last_block |
| 258 | + assert zlib.decompress(deflate_block, wbits=-15) == b"1" |
251 | 259 | f.write(b"2") |
252 | 260 | f.flush() |
253 | | - assert gzip.decompress(test_file.read_bytes()) == b"12" |
| 261 | + data = test_file.read_bytes() |
| 262 | + assert data[-4:] == empty_block_end |
| 263 | + deflate_block = data[10:] + deflate_last_block |
| 264 | + assert zlib.decompress(deflate_block, wbits=-15) == b"12" |
254 | 265 | f.write(b"3") |
255 | 266 | f.flush() |
256 | | - assert gzip.decompress(test_file.read_bytes()) == b"123" |
| 267 | + data = test_file.read_bytes() |
| 268 | + assert data[-4:] == empty_block_end |
| 269 | + deflate_block = data[10:] + deflate_last_block |
| 270 | + assert zlib.decompress(deflate_block, wbits=-15) == b"123" |
257 | 271 | assert gzip.decompress(test_file.read_bytes()) == b"123" |
0 commit comments