Skip to content

Commit d02c2d4

Browse files
committed
Prefer peeking over seeking
This should fix a bug with reading from stdin on Windows under Python 3.11.9+
1 parent 4b2d3ac commit d02c2d4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/dnaio/singleend.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ def _detect_format_from_content(file: BinaryIO) -> Optional[str]:
126126
"""
127127
Return 'fasta', 'fastq' or None
128128
"""
129-
if file.seekable():
129+
if hasattr(file, "peek"):
130+
magic = file.peek(4)[0:4] # type: ignore
131+
else:
132+
# We cannot always use peek() because BytesIO objects do not suppert it
130133
original_position = file.tell()
131134
magic = file.read(4)
132135
file.seek(original_position)
133-
else:
134-
# We cannot always use peek() because BytesIO objects do not suppert it
135-
magic = file.peek(4)[0:4] # type: ignore
136136
if magic.startswith(b"@") or magic == b"":
137137
# Pretend FASTQ for empty input
138138
return "fastq"

0 commit comments

Comments
 (0)