Gzip
application/gzip
Magic Bytes
Offset: 0
1F 8B
Gzip is a compressed file format developed by Jean-loup Gailly and Mark Adler for the GNU Project as a free replacement for the Unix compress utility. It is commonly employed on Unix-like systems to compress single files or data streams and is ubiquitous in web standards to accelerate page loading via HTTP compression. Although generally safe, the format allows for extreme compression ratios that can theoretically facilitate resource exhaustion attacks upon decompression.
Validation Code
How to validate .gz files in Python
Python
def is_gz(file_path: str) -> bool:
"""Check if file is a valid GZ by magic bytes."""
signature = bytes([0x1F, 0x8B])
with open(file_path, "rb") as f:
return f.read(2) == signature
How to validate .gz files in Node.js
Node.js
function isGZ(buffer: Buffer): boolean {
const signature = Buffer.from([0x1F, 0x8B]);
return buffer.subarray(0, 2).equals(signature);
}
Go
func IsGZ(data []byte) bool {
signature := []byte{0x1F, 0x8B}
if len(data) < 2 {
return false
}
return bytes.Equal(data[:2], signature)
}
API Endpoint
GET
/api/v1/gz
curl https://filesignature.org/api/v1/gz