TGZ
application/gzip
Magic Bytes
Offset: 0
1F 8B
TGZ is a compressed archive format that combines the Tar utility with Gzip compression, originally developed for Unix-based systems and maintained by the GNU Project. It serves as a standard method for distributing software packages, source code repositories, and system backups within Linux and macOS environments. While the format itself is secure, users should exercise caution when extracting archives from unknown sources to prevent potential path traversal vulnerabilities or the execution of malicious scripts.
Validation Code
How to validate .tgz files in Python
Python
def is_tgz(file_path: str) -> bool:
"""Check if file is a valid TGZ by magic bytes."""
signature = bytes([0x1F, 0x8B])
with open(file_path, "rb") as f:
return f.read(2) == signature
How to validate .tgz files in Node.js
Node.js
function isTGZ(buffer: Buffer): boolean {
const signature = Buffer.from([0x1F, 0x8B]);
return buffer.subarray(0, 2).equals(signature);
}
Go
func IsTGZ(data []byte) bool {
signature := []byte{0x1F, 0x8B}
if len(data) < 2 {
return false
}
return bytes.Equal(data[:2], signature)
}
API Endpoint
GET
/api/v1/tgz
curl https://filesignature.org/api/v1/tgz