Skip to content

comicbox.box.archive.sniff ΒΆ

Identify file formats by their leading magic bytes.

sniff_ext(data) ΒΆ

Return the file extension for data, or empty if unrecognized.

Source code in comicbox/box/archive/sniff.py
44
45
46
47
48
49
def sniff_ext(data: bytes) -> str:
    """Return the file extension for data, or empty if unrecognized."""
    for magic, ext in _MAGIC_EXTS:
        if data.startswith(magic):
            return ext
    return _sniff_webp(data) or _sniff_pnm(data)