【问题标题】:Examples of Deflate Compression放气压缩的例子
【发布时间】:2015-02-27 02:14:08
【问题描述】:

我有兴趣了解 deflate 压缩算法,特别是它在数据流中的表示方式,并且觉得我会从一些额外的示例中受益匪浅(例如,压缩一小段文本,或者压缩块的解压缩)。 我正在继续研究我发现的一些资源:ref1ref2ref3,但这些资源并没有太多关于实际压缩如何作为数据流的示例。

如果我能得到一些例子来说明一些字符串在被压缩之前和之后的样子,以及它们之间的关系的解释,那就太棒了。

另外,如果还有其他我可以查看的资源,请添加。

【问题讨论】:

    标签: huffman-code deflate


    【解决方案1】:

    您可以使用 gzip 或 zlib 压缩示例数据,并使用 infgen 反汇编并检查生成的压缩数据。 infgen 还可以选择查看动态标题中的详细信息。

    【讨论】:

      【解决方案2】:

      infgen +1,但这里有一个更详细的答案。

      您可以查看使用 gzip 和任何十六进制编辑器之前和之后的情况。例如,大多数 linux 发行版都包含 xxd。我已经包含了原始的十六进制输出(没有理解就不那么有趣)和 infgen 的输出。

      • hello hello hello hello(触发静态霍夫曼编码,就像大多数短字符串一样)。
      ~ $ echo -n "hello hello hello hello" | gzip | xxd
      00000000: 1f8b 0800 0000 0000 0003 cb48 cdc9 c957  ...........H...W
      00000010: c840 2701 e351 3d8d 1700 0000            .@'..Q=.....
      
      ~ $ echo -n "hello hello hello hello" | gzip | ./infgen/a.out -i
      ! infgen 2.4 output
      !
      gzip
      !
      last
      fixed
      literal 'hello h
      match 16 6
      end
      !
      crc
      length
      
      • \xff\xfe\xfd\xfc\xfb\xfa\xf9\xf8\xf7\xf6\xf5\xf4\xf3\xf2\xf1(触发未压缩模式)
      ~ $ echo -ne "\xff\xfe\xfd\xfc\xfb\xfa\xf9\xf8\xf7\xf6\xf5\xf4\xf3\xf2\xf1" | gzip | xxd
      00000000: 1f8b 0800 0000 0000 0003 010f 00f0 ffff  ................
      00000010: fefd fcfb faf9 f8f7 f6f5 f4f3 f2f1 c6d3  ................
      00000020: 157e 0f00 0000                           .~....
      
      ~ $ echo -ne "\xff\xfe\xfd\xfc\xfb\xfa\xf9\xf8\xf7\xf6\xf5\xf4\xf3\xf2\xf1" | gzip | ./infgen/a.out -i
      ! infgen 2.4 output
      !
      gzip
      !
      last
      stored
      data 255 254 253 252 251 250 249 248 247 246 245 244 243 242 241
      end
      !
      crc
      length
      
      • abaabbbabaababbaababaaaabaaabbbbbaa(触发动态霍夫曼编码)
      ~ $ echo -n "abaabbbabaababbaababaaaabaaabbbbbaa" | gzip | xxd
      00000000: 1f8b 0800 0000 0000 0003 1dc6 4901 0000  ............I...
      00000010: 1040 c0ac a37f 883d 3c20 2a97 9d37 5e1d  .@.....=< *..7^.
      00000020: 0c6e 2934 9423 0000 00                   .n)4.#...
      
      ~ $ echo -n "abaabbbabaababbaababaaaabaaabbbbbaa" | gzip | ./infgen/a.out -i -d
      ! infgen 2.4 output
      !
      gzip
      !
      last
      dynamic
      count 260 7 18
      code 1 4
      code 2 1
      code 4 4
      code 16 4
      code 17 4
      code 18 2
      zeros 97
      lens 1 2
      zeros 138
      zeros 19
      lens 4
      repeat 3
      lens 2
      zeros 3
      lens 2 2 2
      ! litlen 97 1
      ! litlen 98 2
      ! litlen 256 4
      ! litlen 257 4
      ! litlen 258 4
      ! litlen 259 4
      ! dist 0 2
      ! dist 4 2
      ! dist 5 2
      ! dist 6 2
      literal 'abaabbba
      match 4 7
      match 3 9
      match 5 6
      literal 'aaa
      match 5 5
      literal 'b
      match 4 1
      literal 'aa
      end
      !
      crc
      length
      

      我发现 infgen 仍然不够详细,无法完全理解格式。我在 my blog987654322@ 上逐位手动解压所有三个示例

      对于概念,除了 RFC 1951 (DEFLATE) 相当不错,我会推荐 Feldspar 的 conceptual overview 的霍夫曼代码和 DEFLATE 中的 LZ77

      【讨论】:

        猜你喜欢
        • 2012-12-09
        • 1970-01-01
        • 2012-08-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-15
        相关资源
        最近更新 更多