使用zlib时如何更改deflate流输出格式(raw,zlib,gzip)?

问题描述 投票:0回答:2

Zlib可以输出three format,我尝试搜索文档和zlib.h,但无法找到关于选项的明确解释,任何人有什么想法?

gzip zlib deflate
2个回答
3
投票

来自zlib.hdeflateInit2()文档:

  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.

1
投票

填空

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 ...)
© www.soinside.com 2019 - 2024. All rights reserved.