pierreinglebert / node-zopfli

Node bindings for Zopfli Compression Algorithm (zlib, gzip, deflate compatible)
MIT License
110 stars 39 forks source link

what's the difference between zlib and gzip? #11

Closed jonathanong closed 10 years ago

dougwilson commented 10 years ago

It is different wrapping for the compressed data. I know the zlib wrapping is used within png streams. zlib is from RFC 1950 and gzip is from RFC 1952. You don't use zlib in HTTP, if that's what you're wondering ;)

pierreinglebert commented 10 years ago

@dougwilson Both can be used in HTTP, zlib is called deflate in encoding headers.

dougwilson commented 10 years ago

From RFC 7230 section 4.2.2:

The "deflate" coding is a "zlib" data format [RFC1950] containing a "deflate" compressed data stream [RFC1951] that uses a combination of the Lempel-Ziv (LZ77) compression algorithm and Huffman coding.

Note: Some non-conformant implementations send the "deflate" compressed data without the zlib wrapper.

i.e. it says you can send the output from the zopfli.zlib method over HTTP marked as deflate, but it is non-conformant since it will be missing the wrapper that the zopfli.deflate method adds.

pierreinglebert commented 10 years ago

I think you inverted methods, zopfli.deflate is a raw deflate, zopfli.zlib is wrapped with the header and the Adler hash footer.

dougwilson commented 10 years ago

Gotcha :) Thanks for the clarification!