add MIME signatures: RPM, AVI, WAV (RIFF subtypes)

This commit is contained in:
Username
2025-12-25 23:51:14 +01:00
parent 4823ff7b5d
commit d7a8f43dae

View File

@@ -84,6 +84,8 @@ MAGIC_SIGNATURES: dict[bytes, str] = {
b"\x04\x22\x4d\x18": "application/x-lz4",
b"7z\xbc\xaf\x27\x1c": "application/x-7z-compressed",
b"Rar!\x1a\x07": "application/vnd.rar",
# Packages
b"\xed\xab\xee\xdb": "application/x-rpm",
# Data
b"SQLite format 3\x00": "application/x-sqlite3",
}
@@ -800,9 +802,16 @@ def detect_mime_type(content: bytes, content_type: str | None = None) -> str:
prefix = content[:MAX_MAGIC_LEN]
for magic, mime in MAGIC_SIGNATURES.items():
if prefix[: len(magic)] == magic:
# RIFF container: verify WEBP subtype
if magic == b"RIFF" and len(content) >= 12 and content[8:12] != b"WEBP":
continue
# RIFF container: check subtype at bytes 8-12
if magic == b"RIFF" and len(content) >= 12:
subtype = content[8:12]
if subtype == b"WEBP":
return "image/webp"
if subtype == b"AVI ":
return "video/x-msvideo"
if subtype == b"WAVE":
return "audio/wav"
continue # Unknown RIFF subtype
return mime
# Explicit Content-Type (if specific)