How to check if a file is gzip compressed?

后端 未结 4 1769
太阳男子
太阳男子 2020-12-03 13:15

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

4条回答
  •  一整个雨季
    2020-12-03 14:02

    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.

提交回复
热议问题