2021-02-24 00:53:05 +01:00
|
|
|
# https://python-forum.io/Thread-read-a-binary-file-to-find-its-type
|
|
|
|
def find_ext(content: bytes) -> str:
|
|
|
|
magic_numbers = {
|
2021-03-01 14:11:18 +01:00
|
|
|
"png": bytes([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A])
|
2021-02-24 00:53:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if content.startswith(magic_numbers["png"]):
|
|
|
|
return "png"
|
|
|
|
|
|
|
|
return "txt"
|