MHT
multipart/related
Magic Bytes
Offset: 0
4D 49 4D 45 2D 56 65 72 73 69 6F 6E 3A 20 31 2E 30
MHTML, commonly known by its .mht extension, is a web archive format standardized by the IETF for combining HTML code and external resources into a single file. It is primarily used by web browsers and email clients to save complete webpages, including images, Flash animations, and Java applets, within a standalone archive. While largely superseded by modern saving methods, this legacy format remains accessible in Microsoft Word and Internet Explorer for offline viewing of static web content.
Validation Code
How to validate .mht files in Python
Python
def is_mht(file_path: str) -> bool:
"""Check if file is a valid MHT by magic bytes."""
signature = bytes([0x4D, 0x49, 0x4D, 0x45, 0x2D, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3A, 0x20, 0x31, 0x2E, 0x30])
with open(file_path, "rb") as f:
return f.read(17) == signature
How to validate .mht files in Node.js
Node.js
function isMHT(buffer: Buffer): boolean {
const signature = Buffer.from([0x4D, 0x49, 0x4D, 0x45, 0x2D, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3A, 0x20, 0x31, 0x2E, 0x30]);
return buffer.subarray(0, 17).equals(signature);
}
Go
func IsMHT(data []byte) bool {
signature := []byte{0x4D, 0x49, 0x4D, 0x45, 0x2D, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3A, 0x20, 0x31, 0x2E, 0x30}
if len(data) < 17 {
return false
}
return bytes.Equal(data[:17], signature)
}
API Endpoint
GET
/api/v1/mht
curl https://filesignature.org/api/v1/mht