How to check if a file is gzip compressed?

后端 未结 4 1768
太阳男子
太阳男子 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:03

    What is the difference in performance between reading compressed and uncompressed files using gzread()?

    Anyway, in order to detect if a file is gzipped, you can read the magic number at the beginning of the file, which is 1f 8b according to the link.

提交回复
热议问题