zip文件格式說明

zip文件由三部分組成:壓縮的文件內容源數據、壓縮的目錄源數據、目錄結束標識結構

1、 壓縮的文件內容源數據:

記錄着壓縮的所有文件的內容信息,其數據組織結構是對於每個文件都由file header 、file data、datadescriptor三部分組成。

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

註釋內容


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章