Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zlib: What is the difference between inflating, encoding, and compressing a string? [duplicate]

Possible Duplicate:
Which compression method to use in PHP?

It seems that PHP has many functions for making smaller strings out of strings. These functions are called inflate/deflate, encode/decode, and compress/uncompress. Some of them seem compatible with each other, as all are base on the zlib library. What is the differences between them, and when to use each?

like image 870
dotancohen Avatar asked Dec 16 '12 09:12

dotancohen


People also ask

What is zlib encoding?

zlib (/ˈziːlɪb/ or "zeta-lib", /ˈziːtəˌlɪb/) is a software library used for data compression. zlib was written by Jean-loup Gailly and Mark Adler and is an abstraction of the DEFLATE compression algorithm used in their gzip file compression program.

What is DEFLATE encoding?

In computing, Deflate (stylized as DEFLATE) is a lossless data compression file format that uses a combination of LZ77 and Huffman coding. It was designed by Phil Katz, for version 2 of his PKZIP archiving tool. Deflate was later specified in RFC 1951 (1996).

Does gzip use zlib?

zlib was adapted from the gzip code. All of the mentioned patents have since expired. The zlib library supports Deflate compression and decompression, and three kinds of wrapping around the deflate streams.

Is zlib lossless?

The zlib compression format is free to use, and is not covered by any patent, so you can safely use it in commercial products as well. It is a lossless compression format (which means you don't lose any data between compression and decompression), and has the advantage of being portable across different platforms.


1 Answers

As stated in the function documentation linked to from the page in your link:

  • gzdeflate - use the 'clean' DEFLATE algorithm with the deflate data format.

  • gzcompress - use the ZLIB data format that add extra header and trailer data on the DEFLATE algorithm. As to RFC 1950 it "can be easily extended to use other compression methods".

  • gzencode - use the gzip application data format that includes some more header data over the ZLIB format.

like image 164
amotzg Avatar answered Oct 02 '22 07:10

amotzg