diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 307b330b..d65c0609 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.9.1 +----------------- ++ Fix BrokenPipeError when piping ``python -m isal.igzip`` into ``head``, + ``less`` or similar programs. + version 1.9.0 ----------------- diff --git a/src/isal/igzip.py b/src/isal/igzip.py index eb9b8042..b18af11c 100644 --- a/src/isal/igzip.py +++ b/src/isal/igzip.py @@ -386,6 +386,9 @@ def main(): try: shutil.copyfileobj(in_file, out_file, args.buffer_size) + except BrokenPipeError: + # Do not throw errors when a pipe to head or less closes. + pass finally: if in_file is not sys.stdin.buffer: in_file.close() diff --git a/tests/test_igzip.py b/tests/test_igzip.py index 6d9cbf5d..457f13f6 100644 --- a/tests/test_igzip.py +++ b/tests/test_igzip.py @@ -769,3 +769,14 @@ def test_small_writes_tell_and_flush(): assert decompressor.decompress(output.getvalue()) == b"abcdef" gzip_file.write(b"gh") assert gzip.decompress(output.getvalue()) == b"abcdefgh" + + +@pytest.mark.skipif(sys.platform != "linux", reason="bash required") +def test_no_broken_pipe(): + subprocess.run( + [ + "bash", "-c", "-e", "-o", "pipefail", + f"{sys.executable} -m isal.igzip -cd {TEST_FILE} | head -n 10" + ], + check=True + )