Skip to content

Commit

Permalink
Prefer peeking over seeking
Browse files Browse the repository at this point in the history
This should fix a bug with reading from stdin on Windows under Python
3.11.9+
  • Loading branch information
marcelm committed Nov 11, 2024
1 parent 4b2d3ac commit d02c2d4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/dnaio/singleend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d02c2d4

Please sign in to comment.