Zip文件格式解析 6.3.3版本
目前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/2007SHA-256/384/5126.3.2 -Added compression method 97 09/28/2007-Documented InfoZIP "Extra Field"values for UTF-8 file name andfile comment storage6.3.3 -Formatting changes to support 09/01/2012easier referencing of this APPNOTEfrom 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
解析中用了 ,故只参考了这部分的格式,如上图中第三、四行,原文
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 bytesversion needed to extract 2 bytesgeneral purpose bit flag 2 bytescompression method 2 byteslast mod file time 2 byteslast mod file date 2 bytescrc-32 4 bytescompressed size 4 bytesuncompressed size 4 bytesfile name length 2 bytesextra field length 2 bytesfile comment length 2 bytesdisk number start 2 bytesinternal file attributes 2 bytesexternal file attributes 4 bytesrelative offset of local header 4 bytesfile 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 – File