TXT
text/plain
Magic Bytes
Offset: 0
FE FF
The TXT format is a universal standard for unstructured plain text, maintained by the International Organization for Standardization and the Unicode Consortium. These files are utilized for system logs, configuration files, source code development, and cross-platform data exchange. While this specific encoding variant supports international character sets and is inherently safe, users should remain cautious of files that mask malicious executable extensions via deceptive naming conventions in graphical user interfaces.
Validation Code
How to validate .txt files in Python
Python
def is_txt(file_path: str) -> bool:
"""Check if file is a valid TXT by magic bytes."""
signature = bytes([0xFE, 0xFF])
with open(file_path, "rb") as f:
return f.read(2) == signature
How to validate .txt files in Node.js
Node.js
function isTXT(buffer: Buffer): boolean {
const signature = Buffer.from([0xFE, 0xFF]);
return buffer.subarray(0, 2).equals(signature);
}
Go
func IsTXT(data []byte) bool {
signature := []byte{0xFE, 0xFF}
if len(data) < 2 {
return false
}
return bytes.Equal(data[:2], signature)
}
API Endpoint
GET
/api/v1/txt
curl https://filesignature.org/api/v1/txt