File tree Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -46,23 +46,21 @@ def _signature_matches_extension(filename, sniff):
46
46
"""
47
47
signatures = {
48
48
".gz" : {"signature" : b"\x1f \x8b " , "format_name" : "gzip" },
49
- ".bz2" : {"signature" : b"\x42 \x5a \x68 " , "format_name" : "bzip2" }
49
+ ".bz2" : {"signature" : b"BZh " , "format_name" : "bzip2" }
50
50
}
51
51
filename = _stringify_path (filename )
52
52
* _ , ext = splitext_addext (filename )
53
53
ext = ext .lower ()
54
54
if ext not in signatures :
55
55
return True , ""
56
56
expected_signature = signatures [ext ]["signature" ]
57
- if sniff is not None and len (sniff ) >= len (expected_signature ):
58
- found_signature = sniff [:len (expected_signature )]
59
- else :
57
+ if sniff is None or len (sniff ) < len (expected_signature ):
60
58
try :
61
59
with open (filename , "rb" ) as fh :
62
- found_signature = fh .read (len (expected_signature ))
60
+ sniff = fh .read (len (expected_signature ))
63
61
except OSError :
64
62
return False , f"Could not read file: { filename } "
65
- if found_signature == expected_signature :
63
+ if not sniff . startswith ( expected_signature ) :
66
64
return True , ""
67
65
format_name = signatures [ext ]["format_name" ]
68
66
return False , f"File { filename } is not a { format_name } file"
You can’t perform that action at this time.
0 commit comments