LZ77: 是一种基于字典的无损数据压缩算法(还有 LZ78, LZW 等) 算法
deflate: 也是一种数据压缩算法,实际上就是先用 LZ77 压缩,而后用霍夫曼编码压缩 函数
gzip: 是一种文件结构,也能够算一种压缩格式,经过 defalte 算法压缩数据,而后加上文件头和CRC校验 编码
zlib: 是一个提供了 deflate, zlib, gzip 压缩方法的函数库;也是一种压缩格式(用 deflate 压缩数据,而后加上 zlib 头和 CRC 校验) code
PHP 中的 zlib 扩展提供了对以上压缩格式的支持,其中的函数和压缩格式的对应关系以下: 接口
gzdeflate, gzinflate 对应 deflate ip
gzcompress, gzuncompress 对应 zlib 格式压缩 string
gzencode, gzdecode 对应 gzip 格式压缩 it
Python 中的 zlib 模块也提供了上述压缩格式的支持,不过接口很“隐晦”: 扩展
zlib.compress 对数据进行 zlib 格式压缩,好像压缩的时候只支持这一种格式,不过你能够经过把压缩后的数据去掉两字节 zlib 头和末尾 4 字节的 CRC 校验获得 deflate 格式的压缩数据(zlib_compressed[2:-4]);对于 gzip 压缩格式能够经过 gzip 模块获得。 sed
zlib.decompress(string[,wbits[,bufsize]]) 解压更折腾,压缩格式是经过 wbits 参数控制的:
另外,对于 Apache 的页面压缩:
Content-Encoding: gzip 对应 gzip 格式压缩
Cotent-Encoding: deflate 对应 deflate 压缩