zlib头文件的样子是什么? [英] What does a zlib header look like?

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

问题描述

在我的项目中,我需要知道 zlib 标题的样子。我听说它很简单,但我找不到任何zlib标题的描述。



例如,它是否包含幻数?

解决方案

链接到RFC

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

CMF(Compression Method and flags)
该字节根据压缩方法分为4位压缩方法和4-
位信息字段。

 位0至3 CM压缩方法
位4至7 CINFO压缩信息

CM(压缩方法)
这标识文件中使用的压缩方法。 CM = 8
表示窗口大小从
到32K的deflate压缩方法。这是gzip和PNG 所使用的方法以及几乎所有其他方法。
CM = 15已保留。



CINFO(压缩信息)
对于CM = 8,CINFO是LZ77窗口
大小的基数2对数减8(CINFO = 7表示32K窗口大小)。在此版本的
规范中,不允许CINFO值大于7的
值。 CINFO在本规范中没有被定义为
CM不等于8。实际上,这意味着第一个字节几乎总是<$ c

FLG(FLaGs)
该标志字节分为以下几部分: 78 (十六进制) / b>

 位0至4 FCHECK(检查CMF和FLG的位)
位5 FDI​​CT(预设字典)
位6至7 FLEVEL(压缩级别)

FCHECK值必须使CMF和FLG,当看作
a以MSB顺序(CMF * 256 + FLG)存储的16位无符号整数时,
是31的倍数。


FLEVEL (压缩级别)
这些标志可供特定压缩
方法使用。 deflate方法( CM = 8 )将这些标志设置为


  0  - 使用压缩器最快算法
1 - 压缩器使用快速算法
2 - 使用压缩器默认算法
3 - 压缩器使用最大压缩,最慢算法


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?

解决方案

Link to RFC

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

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 (Compression method) This identifies the compression method used in the file. CM = 8 denotes the "deflate" compression method with a window size up to 32K. This is the method used by gzip and PNG and almost everything else. CM = 15 is reserved.

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

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

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)

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

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

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆