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
There is a magic number at the beginning of the file. Just read the first two bytes and check if they are equal to 0x1f8b.
0x1f8b