Rich text format word processing
application/rtf
Magic Bytes
Offset: 0
7B 5C 72 74 66 31
Rich Text Format (RTF) is a proprietary document file format developed by Microsoft Corporation for cross-platform document interchange. It serves as a universal standard for word processing, enabling text and basic formatting to be transferred between disparate software applications and operating systems. Although Microsoft ceased development of the specification in 2008, the format remains widely supported due to its simplicity and lower risk profile compared to modern macro-enabled document types.
Validation Code
How to validate .rtf files in Python
Python
def is_rtf(file_path: str) -> bool:
"""Check if file is a valid RTF by magic bytes."""
signature = bytes([0x7B, 0x5C, 0x72, 0x74, 0x66, 0x31])
with open(file_path, "rb") as f:
return f.read(6) == signature
How to validate .rtf files in Node.js
Node.js
function isRTF(buffer: Buffer): boolean {
const signature = Buffer.from([0x7B, 0x5C, 0x72, 0x74, 0x66, 0x31]);
return buffer.subarray(0, 6).equals(signature);
}
Go
func IsRTF(data []byte) bool {
signature := []byte{0x7B, 0x5C, 0x72, 0x74, 0x66, 0x31}
if len(data) < 6 {
return false
}
return bytes.Equal(data[:6], signature)
}
API Endpoint
GET
/api/v1/rtf
curl https://filesignature.org/api/v1/rtf