Skip to content

Commit

Permalink
Add test for bgzip, make sure peek is checked
Browse files Browse the repository at this point in the history
  • Loading branch information
rhpvorderman committed Jul 21, 2023
1 parent c7e8af4 commit 3ae0da4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/isal/igzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def __init__(self, fp):
self._new_member = True
self._last_mtime = None
self._read_buffer_size = READ_BUFFER_SIZE
if detect_bgzip(fp.peek(18)):
if hasattr(fp, "peek") and detect_bgzip(fp.peek(18)):
# bgzip consists of puny little blocks of max 64K uncompressed data
# so in practice probably more around 16K in compressed size. A
# 128K buffer is a massive overshoot and slows down the
Expand Down
Binary file added tests/data/test.fastq.bgzip.gz
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/test_igzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,13 @@ def test_concatenated_gzip():
with igzip.open(concat, "rb") as igzip_h:
result = igzip_h.read()
assert data == result


def test_bgzip():
bgzip_file = Path(__file__).parent / "data" / "test.fastq.bgzip.gz"
gzip_file = Path(__file__).parent / "data" / "test.fastq.gz"
with igzip.open(bgzip_file, "rb") as bgz:
bgz_data = bgz.read()
with igzip.open(gzip_file, "rb") as gz:
gz_data = gz.read()
assert bgz_data == gz_data

0 comments on commit 3ae0da4

Please sign in to comment.