【问题标题】:How to change deflate stream output format(raw, zlib, gzip) when use zlib?使用 zlib 时如何更改 deflate 流输出格式(raw、zlib、gzip)?
【发布时间】:2019-02-13 05:28:05
【问题描述】:

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

【问题讨论】:

    标签: gzip zlib deflate


    【解决方案1】:

    来自deflateInit2()zlib.h文档:

      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.
    

    【讨论】:

    • 为什么使用windowBits 来改变包装文件格式。我以前确实发现过这个,但无法确认。
    • 什么是您无法确认的?它写在文档中。
    • 这里是创建和解压原始DEFLATE流github.com/stokito/deflate的示例
    【解决方案2】:

    填空

    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 ...)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-24
      • 2010-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-09
      • 2021-05-10
      相关资源
      最近更新 更多