Home | History | Annotate | Download | only in DOC
      1 7z Format description (4.59)
      2 ----------------------------
      3 
      4 This file contains description of 7z archive format. 
      5 7z archive can contain files compressed with any method.
      6 See "Methods.txt" for description for defined compressing methods.
      7 
      8 
      9 Format structure Overview
     10 -------------------------
     11 
     12 Some fields can be optional.
     13 
     14 Archive structure
     15 ~~~~~~~~~~~~~~~~~  
     16 SignatureHeader
     17 [PackedStreams]
     18 [PackedStreamsForHeaders]
     19 [
     20   Header 
     21   or 
     22   {
     23     Packed Header
     24     HeaderInfo
     25   }
     26 ]
     27 
     28 
     29 
     30 Header structure
     31 ~~~~~~~~~~~~~~~~  
     32 {
     33   ArchiveProperties
     34   AdditionalStreams
     35   {
     36     PackInfo
     37     {
     38       PackPos
     39       NumPackStreams
     40       Sizes[NumPackStreams]
     41       CRCs[NumPackStreams]
     42     }
     43     CodersInfo
     44     {
     45       NumFolders
     46       Folders[NumFolders]
     47       {
     48         NumCoders
     49         CodersInfo[NumCoders]
     50         {
     51           ID
     52           NumInStreams;
     53           NumOutStreams;
     54           PropertiesSize
     55           Properties[PropertiesSize]
     56         }
     57         NumBindPairs
     58         BindPairsInfo[NumBindPairs]
     59         {
     60           InIndex;
     61           OutIndex;
     62         }
     63         PackedIndices
     64       }
     65       UnPackSize[Folders][Folders.NumOutstreams]
     66       CRCs[NumFolders]
     67     }
     68     SubStreamsInfo
     69     {
     70       NumUnPackStreamsInFolders[NumFolders];
     71       UnPackSizes[]
     72       CRCs[]
     73     }
     74   }
     75   MainStreamsInfo
     76   {
     77     (Same as in AdditionalStreams)
     78   }
     79   FilesInfo
     80   {
     81     NumFiles
     82     Properties[]
     83     {
     84       ID
     85       Size
     86       Data
     87     }
     88   }
     89 }
     90 
     91 HeaderInfo structure
     92 ~~~~~~~~~~~~~~~~~~~~
     93 {
     94   (Same as in AdditionalStreams)
     95 }
     96 
     97 
     98 
     99 Notes about Notation and encoding
    100 ---------------------------------
    101 
    102 7z uses little endian encoding.
    103 
    104 7z archive format has optional headers that are marked as
    105 []
    106 Header
    107 []
    108 
    109 REAL_UINT64 means real UINT64.
    110 
    111 UINT64 means real UINT64 encoded with the following scheme:
    112 
    113   Size of encoding sequence depends from first byte:
    114   First_Byte  Extra_Bytes        Value
    115   (binary)   
    116   0xxxxxxx               : ( xxxxxxx           )
    117   10xxxxxx    BYTE y[1]  : (  xxxxxx << (8 * 1)) + y
    118   110xxxxx    BYTE y[2]  : (   xxxxx << (8 * 2)) + y
    119   ...
    120   1111110x    BYTE y[6]  : (       x << (8 * 6)) + y
    121   11111110    BYTE y[7]  :                         y
    122   11111111    BYTE y[8]  :                         y
    123 
    124 
    125 
    126 Property IDs
    127 ------------
    128 
    129 0x00 = kEnd
    130 
    131 0x01 = kHeader
    132 
    133 0x02 = kArchiveProperties
    134     
    135 0x03 = kAdditionalStreamsInfo
    136 0x04 = kMainStreamsInfo
    137 0x05 = kFilesInfo
    138     
    139 0x06 = kPackInfo
    140 0x07 = kUnPackInfo
    141 0x08 = kSubStreamsInfo
    142 
    143 0x09 = kSize
    144 0x0A = kCRC
    145 
    146 0x0B = kFolder
    147 
    148 0x0C = kCodersUnPackSize
    149 0x0D = kNumUnPackStream
    150 
    151 0x0E = kEmptyStream
    152 0x0F = kEmptyFile
    153 0x10 = kAnti
    154 
    155 0x11 = kName
    156 0x12 = kCTime
    157 0x13 = kATime
    158 0x14 = kMTime
    159 0x15 = kWinAttributes
    160 0x16 = kComment
    161 
    162 0x17 = kEncodedHeader
    163 
    164 0x18 = kStartPos
    165 0x19 = kDummy
    166 
    167 
    168 7z format headers
    169 -----------------
    170 
    171 SignatureHeader
    172 ~~~~~~~~~~~~~~~
    173   BYTE kSignature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};
    174 
    175   ArchiveVersion
    176   {
    177     BYTE Major;   // now = 0
    178     BYTE Minor;   // now = 2
    179   };
    180 
    181   UINT32 StartHeaderCRC;
    182 
    183   StartHeader
    184   {
    185     REAL_UINT64 NextHeaderOffset
    186     REAL_UINT64 NextHeaderSize
    187     UINT32 NextHeaderCRC
    188   }
    189 
    190 
    191 ...........................
    192 
    193 
    194 ArchiveProperties
    195 ~~~~~~~~~~~~~~~~~
    196 BYTE NID::kArchiveProperties (0x02)
    197 for (;;)
    198 {
    199   BYTE PropertyType;
    200   if (aType == 0)
    201     break;
    202   UINT64 PropertySize;
    203   BYTE PropertyData[PropertySize];
    204 }
    205 
    206 
    207 Digests (NumStreams)
    208 ~~~~~~~~~~~~~~~~~~~~~
    209   BYTE AllAreDefined
    210   if (AllAreDefined == 0)
    211   {
    212     for(NumStreams)
    213       BIT Defined
    214   }
    215   UINT32 CRCs[NumDefined]
    216 
    217 
    218 PackInfo
    219 ~~~~~~~~~~~~
    220   BYTE NID::kPackInfo  (0x06)
    221   UINT64 PackPos
    222   UINT64 NumPackStreams
    223 
    224   []
    225   BYTE NID::kSize    (0x09)
    226   UINT64 PackSizes[NumPackStreams]
    227   []
    228 
    229   []
    230   BYTE NID::kCRC      (0x0A)
    231   PackStreamDigests[NumPackStreams]
    232   []
    233 
    234   BYTE NID::kEnd
    235 
    236 
    237 Folder
    238 ~~~~~~
    239   UINT64 NumCoders;
    240   for (NumCoders)
    241   {
    242     BYTE 
    243     {
    244       0:3 CodecIdSize
    245       4:  Is Complex Coder
    246       5:  There Are Attributes
    247       6:  Reserved
    248       7:  There are more alternative methods. (Not used anymore, must be 0).
    249     } 
    250     BYTE CodecId[CodecIdSize]
    251     if (Is Complex Coder)
    252     {
    253       UINT64 NumInStreams;
    254       UINT64 NumOutStreams;
    255     }
    256     if (There Are Attributes)
    257     {
    258       UINT64 PropertiesSize
    259       BYTE Properties[PropertiesSize]
    260     }
    261   }
    262     
    263   NumBindPairs = NumOutStreamsTotal - 1;
    264 
    265   for (NumBindPairs)
    266   {
    267     UINT64 InIndex;
    268     UINT64 OutIndex;
    269   }
    270 
    271   NumPackedStreams = NumInStreamsTotal - NumBindPairs;
    272   if (NumPackedStreams > 1)
    273     for(NumPackedStreams)
    274     {
    275       UINT64 Index;
    276     };
    277 
    278 
    279 
    280 
    281 Coders Info
    282 ~~~~~~~~~~~
    283 
    284   BYTE NID::kUnPackInfo  (0x07)
    285 
    286 
    287   BYTE NID::kFolder  (0x0B)
    288   UINT64 NumFolders
    289   BYTE External
    290   switch(External)
    291   {
    292     case 0:
    293       Folders[NumFolders]
    294     case 1:
    295       UINT64 DataStreamIndex
    296   }
    297 
    298 
    299   BYTE ID::kCodersUnPackSize  (0x0C)
    300   for(Folders)
    301     for(Folder.NumOutStreams)
    302      UINT64 UnPackSize;
    303 
    304 
    305   []
    306   BYTE NID::kCRC   (0x0A)
    307   UnPackDigests[NumFolders]
    308   []
    309 
    310   
    311 
    312   BYTE NID::kEnd
    313 
    314 
    315 
    316 SubStreams Info
    317 ~~~~~~~~~~~~~~
    318   BYTE NID::kSubStreamsInfo; (0x08)
    319 
    320   []
    321   BYTE NID::kNumUnPackStream; (0x0D)
    322   UINT64 NumUnPackStreamsInFolders[NumFolders];
    323   []
    324 
    325 
    326   []
    327   BYTE NID::kSize  (0x09)
    328   UINT64 UnPackSizes[]
    329   []
    330 
    331 
    332   []
    333   BYTE NID::kCRC  (0x0A)
    334   Digests[Number of streams with unknown CRC]
    335   []
    336 
    337   
    338   BYTE NID::kEnd
    339 
    340 
    341 Streams Info
    342 ~~~~~~~~~~~~
    343 
    344   []
    345   PackInfo
    346   []
    347 
    348 
    349   []
    350   CodersInfo
    351   []
    352 
    353 
    354   []
    355   SubStreamsInfo
    356   []
    357 
    358   BYTE NID::kEnd
    359 
    360 
    361 FilesInfo
    362 ~~~~~~~~~
    363   BYTE NID::kFilesInfo;  (0x05)
    364   UINT64 NumFiles
    365 
    366   for (;;)
    367   {
    368     BYTE PropertyType;
    369     if (aType == 0)
    370       break;
    371 
    372     UINT64 Size;
    373 
    374     switch(PropertyType)
    375     {
    376       kEmptyStream:   (0x0E)
    377         for(NumFiles)
    378           BIT IsEmptyStream
    379 
    380       kEmptyFile:     (0x0F)
    381         for(EmptyStreams)
    382           BIT IsEmptyFile
    383 
    384       kAnti:          (0x10)
    385         for(EmptyStreams)
    386           BIT IsAntiFile
    387       
    388       case kCTime: (0x12)
    389       case kATime: (0x13)
    390       case kMTime: (0x14)
    391         BYTE AllAreDefined
    392         if (AllAreDefined == 0)
    393         {
    394           for(NumFiles)
    395             BIT TimeDefined
    396         }
    397         BYTE External;
    398         if(External != 0)
    399           UINT64 DataIndex
    400         []
    401         for(Definded Items)
    402           UINT64 Time
    403         []
    404       
    405       kNames:     (0x11)
    406         BYTE External;
    407         if(External != 0)
    408           UINT64 DataIndex
    409         []
    410         for(Files)
    411         {
    412           wchar_t Names[NameSize];
    413           wchar_t 0;
    414         }
    415         []
    416 
    417       kAttributes:  (0x15)
    418         BYTE AllAreDefined
    419         if (AllAreDefined == 0)
    420         {
    421           for(NumFiles)
    422             BIT AttributesAreDefined
    423         }
    424         BYTE External;
    425         if(External != 0)
    426           UINT64 DataIndex
    427         []
    428         for(Definded Attributes)
    429           UINT32 Attributes
    430         []
    431     }
    432   }
    433 
    434 
    435 Header
    436 ~~~~~~
    437   BYTE NID::kHeader (0x01)
    438 
    439   []
    440   ArchiveProperties
    441   []
    442 
    443   []
    444   BYTE NID::kAdditionalStreamsInfo; (0x03)
    445   StreamsInfo
    446   []
    447 
    448   []
    449   BYTE NID::kMainStreamsInfo;    (0x04)
    450   StreamsInfo
    451   []
    452 
    453   []
    454   FilesInfo
    455   []
    456 
    457   BYTE NID::kEnd
    458 
    459 
    460 HeaderInfo
    461 ~~~~~~~~~~
    462   []
    463   BYTE NID::kEncodedHeader; (0x17)
    464   StreamsInfo for Encoded Header
    465   []
    466 
    467 
    468 ---
    469 End of document
    470