22
22
_compressed_suffixes = ('.gz' , '.bz2' , '.zst' )
23
23
24
24
25
- def _signature_matches_extension (filename , sniff ):
25
+ def _signature_matches_extension (filename ):
26
26
"""Check if signature aka magic number matches filename extension.
27
27
28
28
Parameters
29
29
----------
30
30
filename : str or os.PathLike
31
31
Path to the file to check
32
32
33
- sniff : bytes or None
34
- First bytes of the file. If not `None` and long enough to contain the
35
- signature, avoids having to read the start of the file.
36
-
37
33
Returns
38
34
-------
39
35
matches : bool
@@ -56,12 +52,11 @@ def _signature_matches_extension(filename, sniff):
56
52
if ext not in signatures :
57
53
return True , ""
58
54
expected_signature = signatures [ext ]["signature" ]
59
- if sniff is None or len (sniff ) < len (expected_signature ):
60
- try :
61
- with open (filename , "rb" ) as fh :
62
- sniff = fh .read (len (expected_signature ))
63
- except OSError :
64
- return False , f"Could not read file: { filename } "
55
+ try :
56
+ with open (filename , "rb" ) as fh :
57
+ sniff = fh .read (len (expected_signature ))
58
+ except OSError :
59
+ return False , f"Could not read file: { filename } "
65
60
if sniff .startswith (expected_signature ):
66
61
return True , ""
67
62
format_name = signatures [ext ]["format_name" ]
@@ -100,7 +95,7 @@ def load(filename, **kwargs):
100
95
img = image_klass .from_filename (filename , ** kwargs )
101
96
return img
102
97
103
- matches , msg = _signature_matches_extension (filename , sniff )
98
+ matches , msg = _signature_matches_extension (filename )
104
99
if not matches :
105
100
raise ImageFileError (msg )
106
101
0 commit comments