I have a C / C++ program which needs to read in a file that may or may not be gzip compressed. I know we can use gzread() from zlib to read in both compressed and uncompress
Do you prefer false positives, false negatives, or no false results at all (there goes performance down the drain...)?
The RFC 1952: GZIP file format specification version 4.3 states the first 2 bytes (of each member and therefore) of the file are '\x1F'
and '\x8B'
. Use that for a first check that can result in false positives.