We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ee75f0b commit bc06b43Copy full SHA for bc06b43
filetype/utils.py
@@ -73,14 +73,13 @@ def get_bytes(obj):
73
if isinstance(obj, pathlib.PurePath):
74
return get_signature_bytes(obj)
75
76
- if isinstance(obj, BufferedIOBase):
77
- start_pos = obj.tell()
78
- obj.seek(0)
79
- magic_bytes = obj.read(_NUM_SIGNATURE_BYTES)
80
- obj.seek(start_pos) # restore reader position
81
- return get_bytes(magic_bytes)
82
-
83
if hasattr(obj, 'read'):
+ if hasattr(obj, 'tell') and hasattr(obj, 'seek'):
+ start_pos = obj.tell()
+ obj.seek(0)
+ magic_bytes = obj.read(_NUM_SIGNATURE_BYTES)
+ obj.seek(start_pos)
+ return get_bytes(magic_bytes)
84
return get_bytes(obj.read(_NUM_SIGNATURE_BYTES))
85
86
raise TypeError('Unsupported type as file input: %s' % type(obj))
0 commit comments