Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion filetype/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-

from io import BufferedIOBase

# Python 2.7 workaround
try:
import pathlib
Expand Down Expand Up @@ -57,7 +59,14 @@ def get_bytes(obj):
TypeError: if obj is not a supported type.
"""
try:
obj = obj.read(_NUM_SIGNATURE_BYTES)
if isinstance(obj, BufferedIOBase):
start_position = obj.tell()
obj.seek(0)
buffered_obj = obj
obj = obj.read(_NUM_SIGNATURE_BYTES)
buffered_obj.seek(start_position)
else:
obj = obj.read(_NUM_SIGNATURE_BYTES)
except AttributeError:
# duck-typing as readable failed - we'll try the other options
pass
Expand Down