ZIP文件格式分析

本文深入探讨ZIP文件格式,包括官方文档介绍、压缩源文件数据区的local file header、file data和data descriptor,以及核心目录的End of central directory record。通过样例分析,解释ZIP文件的创建和解析过程。
摘要由CSDN通过智能技术生成

官方文档

https://pkware.cachefly.net/webdocs/APPNOTE/APPNOTE-6.2.0.txt

格式说明

在官方文档中给出的ZIP格式如下:

  Overall .ZIP file format:

    [local file header 1]
    [file data 1]
    [data descriptor 1]
    . 
    .
    .
    [local file header n]
    [file data n]
    [data descriptor n]
    [archive decryption header] (EFS)
    [archive extra data record] (EFS)
    [central directory]
    [zip64 end of central directory record]
    [zip64 end of central directory locator] 
    [end of central directory record]

通常情况下,我们用到的ZIP文件格式:

[local file header + file data + data descriptor]{1,n} + central directory + end of central directory record
即
[文件头+文件数据+数据描述符]{此处可重复n次}+核心目录+目录结束标识

当压缩包中有多个文件时,就会有多个[文件头+文件数据+数据描述符]

本片文章讨论的就是这种通常用到的ZIP文件格式,若想了解完整的ZIP文件格式,请看官方文档。

压缩源文件数据区

[local file header + file data + data descriptor]

记录着压缩的所有文件的内容信息,每个压缩文件都由local file header 、file data、data descriptor三部分组成,在这个数据区中每一个压缩的源文件/目录都是一条记录。

### local file 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 通用比特标志位(置比特0位=加密,详情见后)
8 2 Compression method 压缩方式(详情见后)
10 2 File last modification time 文件最后修改时间
12 2 File last modification date 文件最后修改日期
14 4 CRC-32 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 扩展区
general purpose bit flag: (2 bytes) 通用位标记
      Bit 0: If set, indicates that the file is encrypted.

      (For Method 6 - Imploding)
      Bit 1: If the compression method used 
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值