跳至正文
Wener Notes

zlib

约 2 分钟阅读
标签:压缩RFC
  • 参考
    • ZLIB Compressed Data Format Specification version 3.3
    • DEFLATE Compressed Data Format Specification version 1.3

  • CMF
    • 0-3 CM Compression method
      • 8 -> deflate
    • 4-7 CINFO Compression info
      • CM=8 LZ77 window size, CINFO=7 -> 32K window size
  • FLG
    • 0-4 - FCHECK (check bits for CMF and FLG)
    • 5 - FDICT (preset dictionary)
    • 6-7 - FLEVEL (compression level)
      • 0 - fastest
      • 1 - fast
      • 2 - default
      • 3 - maximum compression, slowest algorithm

bash
file /tmp/data
# /tmp/data: zlib compressed data
printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" | cat - /tmp/data | gzip -dc > /tmp/out
cat /tmp/out

# pigz 并行压缩
brew install pigz
pigz -z test
pigz -d -z test.zz

# openssl zlib -d -in /tmp/data

# qpdf
zlib-flate -uncompress < FILE

Header

LZLIBGZIPNotes
178 011F 8BNo Compression/low
278 5E1F 8BFast Compression
378 5E1F 8B
478 5E1F 8B
578 5E1F 8B
678 9C1F 8BDefault Compression
778 DA1F 8BBest Compression
878 DA1F 8B
978 DA1F 8B
  • CMF -Compression Method and flags
text
bits 0 to 3  CM     Compression method
bits 4 to 7  CINFO  Compression info
  • CM = 8
    • Deflate
    • window size up to 32K
    • used by gzip and PNG
    • CINFO - base-2 logarithm of the LZ77 window size, minus eight
      • CINFO=7 indicates a 32K window size
      • 因此大多前缀都是 78
  • CM = 15
    • reserved
text
bits 0 to 4  FCHECK  (check bits for CMF and FLG)
bit  5       FDICT   (preset dictionary)
bits 6 to 7  FLEVEL  (compression level)
text
 +---+---+
 |CMF|FLG| (2 bytes - Defines the compression mode - More details below)
 +---+---+
 +---+---+---+---+
 |     DICTID    | (4 bytes. Present only when FLG.FDICT is set.) - Mostly not set
 +---+---+---+---+
 +=====================+
 |...compressed data...| (variable size of data)
 +=====================+
 +---+---+---+---+
 |     ADLER32   |  (4 bytes of checksum)
 +---+---+---+---+

关联信息

反向链接、本文链接的其他页面和外部资料。

参考资料

Wikipedia1 条
标准文档2 条
  • RFC 1950datatracker.ietf.org/doc/html/rfc1950
    RFC

    IETF Request for Comments standard document.

  • RFC 1951datatracker.ietf.org/doc/html/rfc1951
    RFC

    IETF Request for Comments standard document.

其他外链1 条
最近更新commit b441539编辑