Some HTTP response messages are compressed in gzip format and need to be decompressed before the data is valid.
http://www.zlib.net/
Provides library functions to understand compression gzip
The example is very detailed, http://www.zlib.net/zlib_how.html
System version: Ubuntu 14.04
Installation Library: Apg-get Install Zlib1g-dev
Compile-time: gcc Xxx-lz
Add header file: #include <zlib.h>
Special attention is paid to:
Example in the
ret = Inflateinit (&STRM);
is the default decompression zlib, if you use it to extract the gzip directly to the message will return Z_DATA_ERROR error, you need to replace the function:
ret = InflateInit2 (&STRM, 47);
In addition: Segmented decompression does not appear to be supported by Inflateinit. Through the test found, although the example is to read the compressed data by the string, and then decompression, seemingly can be segmented decompression, but if each substring of the individual incoming function decompression will be an error. It should be the beginning of the file to be unpacked there will be some initialization information at the beginning of the decompression to give the corresponding function, if the data from the middle of the beginning of the decompression is missing the beginning of the message, so error.
Because this is all for decompression operations, the specific compression function is not discussed.
Under Linux, gzip decompression and compression