0%

压缩.md

1. zlib, gzip

zlib是压缩算法,这个分gunzip和inflate, inflateraw。一般用zlib的默认算法是inflate, python里面的zlib使用的也是inflate。

gzip是文件格式。

2. windowBits

zip里面有个参数windowBits, The wbits argument controls the size of the history buffer (or the “window size”) used when compressing data, and whether a header and trailer is included in the output. It can take several ranges of values. The default is 15.

+9 到 +15:窗口大小以 2 为底的对数。即这些值对应着 512 到 32768 的窗口大小。更大的值会提供更好的压缩,同时内存开销也会更大。压缩输出会包含 zlib 特定格式的头部和尾部。

−9 到 −15:绝对值为窗口大小以 2 为底的对数。压缩输出仅包含压缩数据,没有头部和尾部。

+25 到 +31 = 16 + (9 到 15):后 4 个比特位为窗口大小以 2 为底的对数。压缩输出包含一个基本的 gzip 头部,并以校验和为尾部。

所以如果windowBits为负数,那么就是代表没有头和尾。这个可以让压缩文件结果变小。

node里面不能设置为负数,用inflateRaw也不行。最后使用了ZlibSyncpako.