目前Zip普遍是采用2012年6.3.3版本,目前没有比较新的文章分析6.3.3版的数据格式,查看代码实现解析过程
文件:APPNOTE.TXT - .ZIP文件格式规范
版本:6.3.3
状态:最终版本-替换版本6.3.2
修订日期:2012年9月1日
版权所有(c)1989-2012 PKWARE Inc.,保留所有权利。
Version Change Description Date
------- ------------------ ----------
... ... ...
6.3.1 -Corrected standard hash values for 04/11/2007
SHA-256/384/512
6.3.2 -Added compression method 97 09/28/2007
-Documented InfoZIP "Extra Field"
values for UTF-8 file name and
file comment storage
6.3.3 -Formatting changes to support 09/01/2012
easier referencing of this APPNOTE
from other documents and standards
//翻译:为了支持其他文件和标准更容易引用而 ·更改格式·
数据格式如图所示
文件总体格式,参考图片中第一、第二行
[local file header 1]
[encryption header 1]
[file data 1]
[data descriptor 1]
.
.
.
[local file header n]
[encryption header n]
[file data n]
[data descriptor n]
[archive decryption header]
[archive extra data record]
[central directory header 1]
.
.
.
[central directory header n]
[zip64 end of central directory record]
[zip64 end of central directory locator]
[end of central directory record]
实现解析Zip
解析中用了central directory header,故只参考了这部分的格式,如上图中第三、四行,原文
4.3.12 Central directory structure:
[central directory header 1]
.
.
.
[central directory header n]
[digital signature]
File header:
central file header signature 4 bytes (0x02014b50)
version made by 2 bytes
version needed to extract 2 bytes
general purpose bit flag 2 bytes
compression method 2 bytes
last mod file time 2 bytes
last mod file date 2 bytes
crc-32 4 bytes
compressed size 4 bytes
uncompressed size 4 bytes
file name length 2 bytes
extra field length 2 bytes
file comment length 2 bytes
disk number start 2 bytes
internal file attributes 2 bytes
external file attributes 4 bytes
relative offset of local header 4 bytes
file name (variable size)
extra field (variable size)
file comment (variable size)
6.3.3版原文:Zip 6.3.3 官方说明文档
附录6.2.0版:Zip 6.2.0 官方说明文档(可以对照着看)
查看其他标准信息:ISO/IEC 21320-1 Information technology – Document Container File