• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
17z Format description (4.59)
2----------------------------
3
4This file contains description of 7z archive format.
57z archive can contain files compressed with any method.
6See "Methods.txt" for description for defined compressing methods.
7
8
9Format structure Overview
10-------------------------
11
12Some fields can be optional.
13
14Archive structure
15~~~~~~~~~~~~~~~~~
16SignatureHeader
17[PackedStreams]
18[PackedStreamsForHeaders]
19[
20  Header
21  or
22  {
23    Packed Header
24    HeaderInfo
25  }
26]
27
28
29
30Header 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
91HeaderInfo structure
92~~~~~~~~~~~~~~~~~~~~
93{
94  (Same as in AdditionalStreams)
95}
96
97
98
99Notes about Notation and encoding
100---------------------------------
101
1027z uses little endian encoding.
103
1047z archive format has optional headers that are marked as
105[]
106Header
107[]
108
109REAL_UINT64 means real UINT64.
110
111UINT64 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
126Property IDs
127------------
128
1290x00 = kEnd
130
1310x01 = kHeader
132
1330x02 = kArchiveProperties
134
1350x03 = kAdditionalStreamsInfo
1360x04 = kMainStreamsInfo
1370x05 = kFilesInfo
138
1390x06 = kPackInfo
1400x07 = kUnPackInfo
1410x08 = kSubStreamsInfo
142
1430x09 = kSize
1440x0A = kCRC
145
1460x0B = kFolder
147
1480x0C = kCodersUnPackSize
1490x0D = kNumUnPackStream
150
1510x0E = kEmptyStream
1520x0F = kEmptyFile
1530x10 = kAnti
154
1550x11 = kName
1560x12 = kCTime
1570x13 = kATime
1580x14 = kMTime
1590x15 = kWinAttributes
1600x16 = kComment
161
1620x17 = kEncodedHeader
163
1640x18 = kStartPos
1650x19 = kDummy
166
167
1687z format headers
169-----------------
170
171SignatureHeader
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
194ArchiveProperties
195~~~~~~~~~~~~~~~~~
196BYTE NID::kArchiveProperties (0x02)
197for (;;)
198{
199  BYTE PropertyType;
200  if (aType == 0)
201    break;
202  UINT64 PropertySize;
203  BYTE PropertyData[PropertySize];
204}
205
206
207Digests (NumStreams)
208~~~~~~~~~~~~~~~~~~~~~
209  BYTE AllAreDefined
210  if (AllAreDefined == 0)
211  {
212    for(NumStreams)
213      BIT Defined
214  }
215  UINT32 CRCs[NumDefined]
216
217
218PackInfo
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
237Folder
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
281Coders 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
316SubStreams 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
341Streams 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
361FilesInfo
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
435Header
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
460HeaderInfo
461~~~~~~~~~~
462  []
463  BYTE NID::kEncodedHeader; (0x17)
464  StreamsInfo for Encoded Header
465  []
466
467
468---
469End of document
470