Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
ZIP (file format)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== File headers === All multi-byte values in the header are stored in [[little-endian]] byte order. All length fields count the length in bytes. ==== Local file header ==== {|class="wikitable" |+ Local file header |- ! Offset !! Bytes !! Description<ref name="appnote">{{cite web|url=http://www.pkware.com/documents/casestudies/APPNOTE.TXT|format=TXT|title=File : APPNOTE.TXT - .ZIP File Format Specification : Version: 6.3.4|website=Pkware.com|access-date=2017-09-09}}</ref> |- | 0 || 4 || Local file header signature = 0x04034b50 (PKβ₯β¦ or "PK\3\4") |- | 4 || 2 || Version needed to extract (minimum) |- | 6 || 2 || General purpose bit flag |- | 8 || 2 || Compression method; e.g. none = 0, DEFLATE = 8 (or "\0x08\0x00") |- | 10 || 2 || File last modification time |- | 12 || 2 || File last modification date |- | 14 || 4 || CRC-32 of uncompressed data |- | 18 || 4 || Compressed size (or 0xffffffff for ZIP64) |- | 22 || 4 || Uncompressed size (or 0xffffffff for ZIP64) |- | 26 || 2 || File name length (''n'') |- | 28 || 2 || Extra field length (''m'') |- | 30 || ''n'' || File name |- | 30+''n'' || ''m'' || Extra field |} The extra field contains a variety of optional data such as OS-specific attributes. It is divided into records, each with at minimum a 16-bit signature and a 16-bit length. A ZIP64 local file extra field record, for example, has the signature 0x0001 and a length of 16 bytes (or more) so that two 64-bit values (the uncompressed and compressed sizes) may follow. Another common local file extension is 0x5455 (or "UT") which contains 32-bit UTC UNIX timestamps. This is immediately followed by the compressed data. ==== Data descriptor ==== If the bit at offset 3 (0x08) of the general-purpose flags field is set, then the CRC-32 and file sizes are not known when the header is written. If the archive is in Zip64 format, the compressed and uncompressed size fields are 8 bytes long instead of 4 bytes long (see section 4.3.9.2<ref>{{cite web |title=File: APPNOTE.TXT - .ZIP File Format Specification |url=https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT |publisher=PKWARE Inc. |access-date=21 February 2022}}</ref>). The equivalent fields in the local header (or in the Zip64 extended information extra field in the case of archives in Zip64 format) are filled with zero, and the CRC-32 and size are appended in a 12-byte structure (optionally preceded by a 4-byte signature) immediately after the compressed data: {|class="wikitable" |+ Data descriptor |- ! Offset !! Bytes !! Description<ref name="appnote"/> |- | 0 || 0 or 4 || ''Optional'' data descriptor signature = 0x08074b50 |- | 0 or 4 || 4 || CRC-32 of uncompressed data |- | 4 or 8 || 4 or 8 || Compressed size |- | 8 or 12 or 16|| 4 or 8 || Uncompressed size |} ==== Central directory file header (CDFH) ==== The central directory file header entry is an expanded form of the local header: {|class="wikitable" |+ Central directory file header |- ! Offset !! Bytes !! Description<ref name="appnote"/> |- | 0 || 4 || Central directory file header signature = 0x02014b50 |- | 4 || 2 || Version made by |- | 6 || 2 || Version needed to extract (minimum) |- | 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 of uncompressed data |- | 20 || 4 || Compressed size (or 0xffffffff for ZIP64) |- | 24 || 4 || Uncompressed size (or 0xffffffff for ZIP64) |- | 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 (or 0xffff for ZIP64) |- | 36 || 2 || Internal file attributes |- | 38 || 4 || External file attributes |- | 42 || 4 || Relative offset of local file header (or 0xffffffff for ZIP64). 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. |- | 46 || ''n'' || File name |- | 46+''n'' || ''m'' || Extra field |- | 46+''n''+''m'' || ''k'' || File comment |} ==== End of central directory record (EOCD) ==== After all the central directory entries comes the end of central directory (EOCD) record, which marks the end of the ZIP file: {|class="wikitable" |+ End of central directory record (EOCD) |- ! Offset !! Bytes !! Description<ref name="appnote"/> |- | 0 || 4 || End of central directory signature. '''Must be <code>50 4B 05 06</code>'''. |- | 4 || 2 || Number of this disk (or 0xffff for ZIP64) |- | 6 || 2 || Disk where central directory starts (or 0xffff for ZIP64) |- | 8 || 2 || Number of central directory records on this disk (or 0xffff for ZIP64) |- | 10 || 2 || Total number of central directory records (or 0xffff for ZIP64) |- | 12 || 4 || Size of central directory (bytes) (or 0xffffffff for ZIP64) |- | 16 || 4 || Offset of start of central directory, relative to start of archive (or 0xffffffff for ZIP64) |- | 20 || 2 || Comment length (''n'') |- | 22 || ''n'' || Comment |} This ordering allows a ZIP file to be created in one pass, but the central directory is also placed at the end of the file in order to facilitate easy removal of files from multiple-part ''(e.g. "multiple floppy-disk")'' archives, as previously discussed.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)