Zlib
can output three format, I try to search the docs and zlib.h
, but can't find a clear explanation about the options, anyone have any ideas?
Asked
Active
Viewed 1,609 times
2 Answers
3
From the zlib.h documentation of deflateInit2()
:
windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
determines the window size. deflate() will then generate raw deflate data
with no zlib header or trailer, and will not compute a check value.
windowBits can also be greater than 15 for optional gzip encoding. Add
16 to windowBits to write a simple gzip header and trailer around the
compressed data instead of a zlib wrapper.

Mark Adler
- 101,978
- 13
- 118
- 158
-
Why use `windowBits ` to alter the wrapper file format. I really found this before, but can't confirm that. – Karl Feb 14 '19 at 04:12
-
What is it that you can't confirm? It's written right there in the documentation. – Mark Adler Feb 14 '19 at 04:36
-
here is an example of creation and decompression of raw DEFLATE stream https://github.com/stokito/deflate – Sergey Ponomarev Jun 08 '20 at 20:25
1
Fill in the blanks
int get_file_format(int n) {
if (n == 0) return 31;
else if (n == 1) return 15;
else if (n == 2) return -15;
else if (n >= 9 && n <= 15) return n; /* zlib with window size 2^9 to 2^15 */
else if (n >= 25 && n <= 31) return n; /* gzip with window size 2^9 to 2^15 */
else if (n >= -15 && n <= -9)return n; /* raw with window size 2^9 to 2^15 */
else return Z_ERRNO;
}
z_hist_sz = get_file_format(n);
ret = deflateInit2(&strm, COMPRESS_LEVEL, Z_DEFLATED, z_hist_sz ...)

B Abali
- 433
- 2
- 10