Jul18

Zip文件数据结构说明

Author: leeon  Click: 8468   Date: 2014.07.18 @ 23:00:03 pm Category: 算法

zip文件由三部分组成:压缩的文件内容源数据、压缩的目录源数据、目录结束标识结构

1、 压缩的文件内容源数据:

记录着压缩的所有文件的内容信息,其数据组织结构是对于每个文件都由file header 、file data、data descriptor三部分组成。

1)File header:用于标识该文件的开始,结构说明如下:

 

                               Header

Offset

Bytes

Description

0

4

Local file header signature = 0x04034b50 (read as a little-endian number)

文件头标识,值固定(0x04034b50)

4

2

Version needed to extract (minimum)

解压文件所需 pkware最低 版本 

6

2

General purpose bit flag

通用位标记

8

2

Compression method

压缩方法

10

2

File last modification time

文件最后修改时间

12

2

File last modification date

文件最后修改日期

14

4

CRC-32

说明采用的算法。

18

4

Compressed size

压缩后的大小。

22

4

Uncompressed size

非压缩的大小。

26

2

File name length (n)

文件名长度

28

2

Extra field length (m)

扩展区长度

30

n

File name

文件名

30+n

m

Extra field

扩展区

 

2)file data :相应压缩文件的源数据。

 

3)data descriptor:用于标识该文件压缩结束,该结构只有在相应的header中通用标记字段的第3位设为1时才会出现,紧接在压缩文件源数据后。这个数据描述符只用在不能对输出的 ZIP 文件进行检索时使用。例如:在一个不能检索的驱动器(如:磁带机上)上的 ZIP 文件中。如果是磁盘上的ZIP文件一般没有这个数据描述符。

结构说明如下

   Data descriptor

Offset

Bytes

Description[18]

 0

4

Local file header signature = 0x08074b50

本地header标记

 4

4

CRC-32

CRC-32

 8

4

Compressed size

压缩后大小

 12

4

Uncompressed size

非压缩的大小

 

2、 压缩的目录源数据

对于待压缩的目录而言,每一个子目录对应一个压缩目录源数据,记录该目录的描述信息。压缩包中所有目录源数据连续存储在整个归档包的最后,这样便于向包中追加新的文件。

结构说明如下

Central directory file header

 

Offset

Bytes

Description[18]

 0

4

Central directory file header signature =0x02014b50

核心目录文件header标识=(0x02014b50)

 4

2

Version made by

压缩所用的pkware版本

 6

2

Version needed to extract (minimum)

解压所需pkware的最低版本

 8

2

General purpose bit flag

通用位标记

10

2

Compression method

压缩方法

12

2

File last modification time

文件最后修改时间

14

2

File last modification date

文件最后修改日期

16

4

CRC-32

CRC-32算法

20

4

Compressed size

压缩后大小

24

4

Uncompressed size

未压缩的大小

28

2

File name length (n)

文件名长度

30

2

Extra field length (m)

扩展域长度

32

2

File comment length (k)

文件注释长度

34

2

Disk number where file starts

文件开始位置的磁盘编号

36

2

Internal file attributes

内部文件属性

38

4

External file attributes

外部文件属性

42

4

Relative offset of local file header. This is the number of bytes between the start of the first disk on which the file occurs, and the start of the local file header. This allows software reading the central directory to locate the position of the file inside the ZIP file.

本地文件header的相对位移。

46

n

File name

目录文件名

46+n

m

Extra field

扩展域

46+n+m

k

File comment

文件注释内容

 

3、 目录结束标识结构

目录结束标识存在于整个归档包的结尾,用于标记压缩的目录数据的结束。

结构说明如下

End of central directory record

Offset

Bytes

Description[18]

 0

4

End of central directory signature =0x06054b50

核心目录结束标记(0x06054b50)

 4

2

Number of this disk

当前磁盘编号

 6

2

Disk where central directory starts

核心目录开始位置的磁盘编号

 8

2

Number of central directory records on this disk

该磁盘上所记录的核心目录数量

10

2

Total number of central directory records

核心目录结构总数

12

4

Size of central directory (bytes)

核心目录的大小

16

4

Offset of start of central directory, relative to start of archive

核心目录开始位置相对于archive开始的位移

20

2

Comment length (n)

注释长度

22

n

Comment

注释内容



TAG:   zip

    评论
    • 提交

    分类

    标签

    归档

    最新评论

    Abyss在00:04:28评论了
    Linux中ramdisk,tmpfs,ramfs的介绍与性能测试
    shallwe99在10:21:17评论了
    【原创】如何在微信小程序开发中正确的使用vant ui组件
    默一在09:04:53评论了
    Berkeley DB 由浅入深【转自架构师杨建】
    Memory在14:09:22评论了
    【原创】最佳PHP框架选择(phalcon,yaf,laravel,thinkphp,yii)
    leo在17:57:04评论了
    shell中使用while循环ssh的注意事项

    我看过的书

    链接

    其他

    访问本站种子 本站平均热度:8823 c° 本站链接数:1 个 本站标签数:464 个 本站被评论次数:94 次