Translations: Update the Polish translation.
[xz.git] / doc / lzma-file-format.txt
blob1dd365eb6cf47d424d8839a25b5be418c71e2d40
2 The .lzma File Format
3 =====================
5         0. Preface
6            0.1. Notices and Acknowledgements
7            0.2. Changes
8         1. File Format
9            1.1. Header
10                 1.1.1. Properties
11                 1.1.2. Dictionary Size
12                 1.1.3. Uncompressed Size
13            1.2. LZMA Compressed Data
14         2. References
17 0. Preface
19         This document describes the .lzma file format, which is
20         sometimes also called LZMA_Alone format. It is a legacy file
21         format, which is being or has been replaced by the .xz format.
22         The MIME type of the .lzma format is `application/x-lzma'.
24         The most commonly used software to handle .lzma files are
25         LZMA SDK, LZMA Utils, 7-Zip, and XZ Utils. This document
26         describes some of the differences between these implementations
27         and gives hints what subset of the .lzma format is the most
28         portable.
31 0.1. Notices and Acknowledgements
33         This file format was designed by Igor Pavlov for use in
34         LZMA SDK. This document was written by Lasse Collin
35         <lasse.collin@tukaani.org> using the documentation found
36         from the LZMA SDK.
38         This document has been put into the public domain.
41 0.2. Changes
43         Last modified: 2024-01-16 18:00+0800
45         Compared to the previous version (2022-07-13 21:00+0300)
46         the section 2 was modified to change links from http to
47         https and to update XZ links.
50 1. File Format
52         +-+-+-+-+-+-+-+-+-+-+-+-+-+==========================+
53         |         Header          |   LZMA Compressed Data   |
54         +-+-+-+-+-+-+-+-+-+-+-+-+-+==========================+
56         The .lzma format file consist of 13-byte Header followed by
57         the LZMA Compressed Data.
59         Unlike the .gz, .bz2, and .xz formats, it is not possible to
60         concatenate multiple .lzma files as is and expect the
61         decompression tool to decode the resulting file as if it were
62         a single .lzma file.
64         For example, the command line tools from LZMA Utils and
65         LZMA SDK silently ignore all the data after the first .lzma
66         stream. In contrast, the command line tool from XZ Utils
67         considers the .lzma file to be corrupt if there is data after
68         the first .lzma stream.
71 1.1. Header
73         +------------+----+----+----+----+--+--+--+--+--+--+--+--+
74         | Properties |  Dictionary Size  |   Uncompressed Size   |
75         +------------+----+----+----+----+--+--+--+--+--+--+--+--+
78 1.1.1. Properties
80         The Properties field contains three properties. An abbreviation
81         is given in parentheses, followed by the value range of the
82         property. The field consists of
84             1) the number of literal context bits (lc, [0, 8]);
85             2) the number of literal position bits (lp, [0, 4]); and
86             3) the number of position bits (pb, [0, 4]).
88         The properties are encoded using the following formula:
90             Properties = (pb * 5 + lp) * 9 + lc
92         The following C code illustrates a straightforward way to
93         decode the Properties field:
95             uint8_t lc, lp, pb;
96             uint8_t prop = get_lzma_properties();
97             if (prop > (4 * 5 + 4) * 9 + 8)
98                 return LZMA_PROPERTIES_ERROR;
100             pb = prop / (9 * 5);
101             prop -= pb * 9 * 5;
102             lp = prop / 9;
103             lc = prop - lp * 9;
105         XZ Utils has an additional requirement: lc + lp <= 4. Files
106         which don't follow this requirement cannot be decompressed
107         with XZ Utils. Usually this isn't a problem since the most
108         common lc/lp/pb values are 3/0/2. It is the only lc/lp/pb
109         combination that the files created by LZMA Utils can have,
110         but LZMA Utils can decompress files with any lc/lp/pb.
113 1.1.2. Dictionary Size
115         Dictionary Size is stored as an unsigned 32-bit little endian
116         integer. Any 32-bit value is possible, but for maximum
117         portability, only sizes of 2^n and 2^n + 2^(n-1) should be
118         used.
120         LZMA Utils creates only files with dictionary size 2^n,
121         16 <= n <= 25. LZMA Utils can decompress files with any
122         dictionary size.
124         XZ Utils creates and decompresses .lzma files only with
125         dictionary sizes 2^n and 2^n + 2^(n-1). If some other
126         dictionary size is specified when compressing, the value
127         stored in the Dictionary Size field is a rounded up, but the
128         specified value is still used in the actual compression code.
131 1.1.3. Uncompressed Size
133         Uncompressed Size is stored as unsigned 64-bit little endian
134         integer. A special value of 0xFFFF_FFFF_FFFF_FFFF indicates
135         that Uncompressed Size is unknown. End of Payload Marker (*)
136         is used if Uncompressed Size is unknown. End of Payload Marker
137         is allowed but rarely used if Uncompressed Size is known.
138         XZ Utils 5.2.5 and older don't support .lzma files that have
139         End of Payload Marker together with a known Uncompressed Size.
141         XZ Utils rejects files whose Uncompressed Size field specifies
142         a known size that is 256 GiB or more. This is to reject false
143         positives when trying to guess if the input file is in the
144         .lzma format. When Uncompressed Size is unknown, there is no
145         limit for the uncompressed size of the file.
147         (*) Some tools use the term End of Stream (EOS) marker
148             instead of End of Payload Marker.
151 1.2. LZMA Compressed Data
153         Detailed description of the format of this field is out of
154         scope of this document.
157 2. References
159         LZMA SDK - The original LZMA implementation
160         https://7-zip.org/sdk.html
162         7-Zip
163         https://7-zip.org/
165         LZMA Utils - LZMA adapted to POSIX-like systems
166         https://tukaani.org/lzma/
168         XZ Utils - The next generation of LZMA Utils
169         https://xz.tukaani.org/xz-utils/
171         The .xz file format - The successor of the .lzma format
172         https://xz.tukaani.org/format/xz-file-format.txt