Under Linux, gzip decompression and compression

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.