From d02c2d41bf97b45d7e846eeedd2c6c697914057d Mon Sep 17 00:00:00 2001 From: Marcel Martin Date: Mon, 11 Nov 2024 16:26:36 +0100 Subject: [PATCH] Prefer peeking over seeking This should fix a bug with reading from stdin on Windows under Python 3.11.9+ --- src/dnaio/singleend.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dnaio/singleend.py b/src/dnaio/singleend.py index 7d8d79df..8a49b496 100644 --- a/src/dnaio/singleend.py +++ b/src/dnaio/singleend.py @@ -126,13 +126,13 @@ def _detect_format_from_content(file: BinaryIO) -> Optional[str]: """ Return 'fasta', 'fastq' or None """ - if file.seekable(): + if hasattr(file, "peek"): + magic = file.peek(4)[0:4] # type: ignore + else: + # We cannot always use peek() because BytesIO objects do not suppert it original_position = file.tell() magic = file.read(4) file.seek(original_position) - else: - # We cannot always use peek() because BytesIO objects do not suppert it - magic = file.peek(4)[0:4] # type: ignore if magic.startswith(b"@") or magic == b"": # Pretend FASTQ for empty input return "fastq"