From 1b23073d399d2c6f139f6e00f76501064e816c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20G=C3=BCnter=20Herforth?= Date: Mon, 15 Jul 2024 14:18:26 +0200 Subject: [PATCH] Add gzip decompression from file --- bioread/reader.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bioread/reader.py b/bioread/reader.py index 6f6a8f6..8debdb9 100644 --- a/bioread/reader.py +++ b/bioread/reader.py @@ -12,6 +12,8 @@ from __future__ import with_statement, division import struct import zlib +import gzip +import io as pyio from contextlib import contextmanager import numpy as np @@ -80,6 +82,14 @@ def read(cls, returns: reader.Reader. """ + + # decompresses gzip file into memory + if isinstance(fo, str) and fo.endswith('.gz'): + with gzip.open(fo, 'rb') as compressed_fo: + decompressed_data = compressed_fo.read() + fo = pyio.BytesIO(decompressed_data) + + with open_or_yield(fo, 'rb') as io: reader = cls(io) reader._read_headers()