本文介绍了zlib 标头是什么样的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我需要知道 zlib 标头是什么样的.我听说这很简单,但我找不到 zlib 标头的任何描述.

In my project I need to know what a zlib header looks like. I've heard it's rather simple but I cannot find any description of the zlib header.

例如,它是否包含幻数?

For example, does it contain a magic number?

推荐答案

链接到 RFC

0   1
+---+---+
|CMF|FLG|
+---+---+

CMF(压缩方法和标志)该字节分为 4 位压缩方法和 4-位信息字段取决于压缩方法.

CMF (Compression Method and flags)This byte is divided into a 4-bit compression method and a 4-bit information field depending on the compression method.

bits 0 to 3  CM     Compression method
bits 4 to 7  CINFO  Compression info

CM(压缩方法)这标识了文件中使用的压缩方法.CM = 8表示放气";窗口大小增大的压缩方法到 32K.这是 gzip 和 PNG 以及几乎所有其他东西使用的方法.CM = 15 被保留.

CM (Compression method)This identifies the compression method used in the file. CM = 8denotes the "deflate" compression method with a window size upto 32K. This is the method used by gzip and PNG and almost everything else.CM = 15 is reserved.

CINFO(压缩信息)对于 CM = 8,CINFO 是 LZ77 窗口的以 2 为底的对数大小,减八(CINFO=7 表示 32K 窗口大小).价值观CINFO 7 以上的在这个版本中是不允许的规格.CINFO 未在本规范中定义CM 不等于 8.

CINFO (Compression info)For CM = 8, CINFO is the base-2 logarithm of the LZ77 windowsize, minus eight (CINFO=7 indicates a 32K window size). Valuesof CINFO above 7 are not allowed in this version of thespecification. CINFO is not defined in this specification forCM not equal to 8.

实际上,这意味着第一个字节几乎总是78(十六进制)

In practice, this means the first byte is almost always 78 (hex)

FLG(标志)该标志字节划分如下:

FLG (FLaGs)This flag byte is divided as follows:

bits 0 to 4  FCHECK  (check bits for CMF and FLG)
bit  5       FDICT   (preset dictionary)
bits 6 to 7  FLEVEL  (compression level)

FCHECK 值必须是 CMF 和 FLG,当被视为以 MSB 顺序存储的 16 位无符号整数 (CMF*256 + FLG),是 31 的倍数.

The FCHECK value must be such that CMF and FLG, when viewed asa 16-bit unsigned integer stored in MSB order (CMF*256 + FLG),is a multiple of 31.

FLEVEL(压缩级别)这些标志可供特定压缩使用方法.放气"方法 (CM = 8) 将这些标志设置为如下:

FLEVEL (Compression level)These flags are available for use by specific compressionmethods. The "deflate" method (CM = 8) sets these flags asfollows:

        0 - compressor used fastest algorithm
        1 - compressor used fast algorithm
        2 - compressor used default algorithm
        3 - compressor used maximum compression, slowest algorithm

这篇关于zlib 标头是什么样的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!