• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1LZMA SDK 18.06
2--------------
3
4LZMA SDK provides the documentation, samples, header files,
5libraries, and tools you need to develop applications that
6use 7z / LZMA / LZMA2 / XZ compression.
7
8LZMA is an improved version of famous LZ77 compression algorithm.
9It was improved in way of maximum increasing of compression ratio,
10keeping high decompression speed and low memory requirements for
11decompressing.
12
13LZMA2 is a LZMA based compression method. LZMA2 provides better
14multithreading support for compression than LZMA and some other improvements.
15
167z is a file format for data compression and file archiving.
177z is a main file format for 7-Zip compression program (www.7-zip.org).
187z format supports different compression methods: LZMA, LZMA2 and others.
197z also supports AES-256 based encryption.
20
21XZ is a file format for data compression that uses LZMA2 compression.
22XZ format provides additional features: SHA/CRC check, filters for
23improved compression ratio, splitting to blocks and streams,
24
25
26
27LICENSE
28-------
29
30LZMA SDK is written and placed in the public domain by Igor Pavlov.
31
32Some code in LZMA SDK is based on public domain code from another developers:
33  1) PPMd var.H (2001): Dmitry Shkarin
34  2) SHA-256: Wei Dai (Crypto++ library)
35
36Anyone is free to copy, modify, publish, use, compile, sell, or distribute the
37original LZMA SDK code, either in source code form or as a compiled binary, for
38any purpose, commercial or non-commercial, and by any means.
39
40LZMA SDK code is compatible with open source licenses, for example, you can
41include it to GNU GPL or GNU LGPL code.
42
43
44LZMA SDK Contents
45-----------------
46
47  Source code:
48
49    - C / C++ / C# / Java   - LZMA compression and decompression
50    - C / C++               - LZMA2 compression and decompression
51    - C / C++               - XZ compression and decompression
52    - C                     - 7z decompression
53    -     C++               - 7z compression and decompression
54    - C                     - small SFXs for installers (7z decompression)
55    -     C++               - SFXs and SFXs for installers (7z decompression)
56
57  Precomiled binaries:
58
59    - console programs for lzma / 7z / xz compression and decompression
60    - SFX modules for installers.
61
62
63UNIX/Linux version
64------------------
65To compile C++ version of file->file LZMA encoding, go to directory
66CPP/7zip/Bundles/LzmaCon
67and call make to recompile it:
68  make -f makefile.gcc clean all
69
70In some UNIX/Linux versions you must compile LZMA with static libraries.
71To compile with static libraries, you can use
72LIB = -lm -static
73
74Also you can use p7zip (port of 7-Zip for POSIX systems like Unix or Linux):
75
76  http://p7zip.sourceforge.net/
77
78
79Files
80-----
81
82DOC/7zC.txt          - 7z ANSI-C Decoder description
83DOC/7zFormat.txt     - 7z Format description
84DOC/installer.txt    - information about 7-Zip for installers
85DOC/lzma.txt         - LZMA compression description
86DOC/lzma-sdk.txt     - LZMA SDK description (this file)
87DOC/lzma-history.txt - history of LZMA SDK
88DOC/lzma-specification.txt - Specification of LZMA
89DOC/Methods.txt      - Compression method IDs for .7z
90
91bin/installer/   - example script to create installer that uses SFX module,
92
93bin/7zdec.exe    - simplified 7z archive decoder
94bin/7zr.exe      - 7-Zip console program (reduced version)
95bin/x64/7zr.exe  - 7-Zip console program (reduced version) (x64 version)
96bin/lzma.exe     - file->file LZMA encoder/decoder for Windows
97bin/7zS2.sfx     - small SFX module for installers (GUI version)
98bin/7zS2con.sfx  - small SFX module for installers (Console version)
99bin/7zSD.sfx     - SFX module for installers.
100
101
1027zDec.exe
103---------
1047zDec.exe is simplified 7z archive decoder.
105It supports only LZMA, LZMA2, and PPMd methods.
1067zDec decodes whole solid block from 7z archive to RAM.
107The RAM consumption can be high.
108
109
110
111
112Source code structure
113---------------------
114
115
116Asm/ - asm files (optimized code for CRC calculation and Intel-AES encryption)
117
118C/  - C files (compression / decompression and other)
119  Util/
120    7z       - 7z decoder program (decoding 7z files)
121    Lzma     - LZMA program (file->file LZMA encoder/decoder).
122    LzmaLib  - LZMA library (.DLL for Windows)
123    SfxSetup - small SFX module for installers
124
125CPP/ -- CPP files
126
127  Common  - common files for C++ projects
128  Windows - common files for Windows related code
129
130  7zip    - files related to 7-Zip
131
132    Archive - files related to archiving
133
134      Common   - common files for archive handling
135      7z       - 7z C++ Encoder/Decoder
136
137    Bundles  - Modules that are bundles of other modules (files)
138
139      Alone7z       - 7zr.exe: Standalone 7-Zip console program (reduced version)
140      Format7zExtractR  - 7zxr.dll: Reduced version of 7z DLL: extracting from 7z/LZMA/BCJ/BCJ2.
141      Format7zR         - 7zr.dll:  Reduced version of 7z DLL: extracting/compressing to 7z/LZMA/BCJ/BCJ2
142      LzmaCon       - lzma.exe: LZMA compression/decompression
143      LzmaSpec      - example code for LZMA Specification
144      SFXCon        - 7zCon.sfx: Console 7z SFX module
145      SFXSetup      - 7zS.sfx: 7z SFX module for installers
146      SFXWin        - 7z.sfx: GUI 7z SFX module
147
148    Common   - common files for 7-Zip
149
150    Compress - files for compression/decompression
151
152    Crypto   - files for encryption / decompression
153
154    UI       - User Interface files
155
156      Client7z - Test application for 7za.dll, 7zr.dll, 7zxr.dll
157      Common   - Common UI files
158      Console  - Code for console program (7z.exe)
159      Explorer    - Some code from 7-Zip Shell extension
160      FileManager - Some GUI code from 7-Zip File Manager
161      GUI         - Some GUI code from 7-Zip
162
163
164CS/ - C# files
165  7zip
166    Common   - some common files for 7-Zip
167    Compress - files related to compression/decompression
168      LZ     - files related to LZ (Lempel-Ziv) compression algorithm
169      LZMA         - LZMA compression/decompression
170      LzmaAlone    - file->file LZMA compression/decompression
171      RangeCoder   - Range Coder (special code of compression/decompression)
172
173Java/  - Java files
174  SevenZip
175    Compression    - files related to compression/decompression
176      LZ           - files related to LZ (Lempel-Ziv) compression algorithm
177      LZMA         - LZMA compression/decompression
178      RangeCoder   - Range Coder (special code of compression/decompression)
179
180
181Note:
182  Asm / C / C++ source code of LZMA SDK is part of 7-Zip's source code.
183  7-Zip's source code can be downloaded from 7-Zip's SourceForge page:
184
185  http://sourceforge.net/projects/sevenzip/
186
187
188
189LZMA features
190-------------
191  - Variable dictionary size (up to 1 GB)
192  - Estimated compressing speed: about 2 MB/s on 2 GHz CPU
193  - Estimated decompressing speed:
194      - 20-30 MB/s on modern 2 GHz cpu
195      - 1-2 MB/s on 200 MHz simple RISC cpu: (ARM, MIPS, PowerPC)
196  - Small memory requirements for decompressing (16 KB + DictionarySize)
197  - Small code size for decompressing: 5-8 KB
198
199LZMA decoder uses only integer operations and can be
200implemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).
201
202Some critical operations that affect the speed of LZMA decompression:
203  1) 32*16 bit integer multiply
204  2) Mispredicted branches (penalty mostly depends from pipeline length)
205  3) 32-bit shift and arithmetic operations
206
207The speed of LZMA decompressing mostly depends from CPU speed.
208Memory speed has no big meaning. But if your CPU has small data cache,
209overall weight of memory speed will slightly increase.
210
211
212How To Use
213----------
214
215Using LZMA encoder/decoder executable
216--------------------------------------
217
218Usage:  LZMA <e|d> inputFile outputFile [<switches>...]
219
220  e: encode file
221
222  d: decode file
223
224  b: Benchmark. There are two tests: compressing and decompressing
225     with LZMA method. Benchmark shows rating in MIPS (million
226     instructions per second). Rating value is calculated from
227     measured speed and it is normalized with Intel's Core 2 results.
228     Also Benchmark checks possible hardware errors (RAM
229     errors in most cases). Benchmark uses these settings:
230     (-a1, -d21, -fb32, -mfbt4). You can change only -d parameter.
231     Also you can change the number of iterations. Example for 30 iterations:
232       LZMA b 30
233     Default number of iterations is 10.
234
235<Switches>
236
237
238  -a{N}:  set compression mode 0 = fast, 1 = normal
239          default: 1 (normal)
240
241  d{N}:   Sets Dictionary size - [0, 30], default: 23 (8MB)
242          The maximum value for dictionary size is 1 GB = 2^30 bytes.
243          Dictionary size is calculated as DictionarySize = 2^N bytes.
244          For decompressing file compressed by LZMA method with dictionary
245          size D = 2^N you need about D bytes of memory (RAM).
246
247  -fb{N}: set number of fast bytes - [5, 273], default: 128
248          Usually big number gives a little bit better compression ratio
249          and slower compression process.
250
251  -lc{N}: set number of literal context bits - [0, 8], default: 3
252          Sometimes lc=4 gives gain for big files.
253
254  -lp{N}: set number of literal pos bits - [0, 4], default: 0
255          lp switch is intended for periodical data when period is
256          equal 2^N. For example, for 32-bit (4 bytes)
257          periodical data you can use lp=2. Often it's better to set lc0,
258          if you change lp switch.
259
260  -pb{N}: set number of pos bits - [0, 4], default: 2
261          pb switch is intended for periodical data
262          when period is equal 2^N.
263
264  -mf{MF_ID}: set Match Finder. Default: bt4.
265              Algorithms from hc* group doesn't provide good compression
266              ratio, but they often works pretty fast in combination with
267              fast mode (-a0).
268
269              Memory requirements depend from dictionary size
270              (parameter "d" in table below).
271
272               MF_ID     Memory                   Description
273
274                bt2    d *  9.5 + 4MB  Binary Tree with 2 bytes hashing.
275                bt3    d * 11.5 + 4MB  Binary Tree with 3 bytes hashing.
276                bt4    d * 11.5 + 4MB  Binary Tree with 4 bytes hashing.
277                hc4    d *  7.5 + 4MB  Hash Chain with 4 bytes hashing.
278
279  -eos:   write End Of Stream marker. By default LZMA doesn't write
280          eos marker, since LZMA decoder knows uncompressed size
281          stored in .lzma file header.
282
283  -si:    Read data from stdin (it will write End Of Stream marker).
284  -so:    Write data to stdout
285
286
287Examples:
288
2891) LZMA e file.bin file.lzma -d16 -lc0
290
291compresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)
292and 0 literal context bits. -lc0 allows to reduce memory requirements
293for decompression.
294
295
2962) LZMA e file.bin file.lzma -lc0 -lp2
297
298compresses file.bin to file.lzma with settings suitable
299for 32-bit periodical data (for example, ARM or MIPS code).
300
3013) LZMA d file.lzma file.bin
302
303decompresses file.lzma to file.bin.
304
305
306Compression ratio hints
307-----------------------
308
309Recommendations
310---------------
311
312To increase the compression ratio for LZMA compressing it's desirable
313to have aligned data (if it's possible) and also it's desirable to locate
314data in such order, where code is grouped in one place and data is
315grouped in other place (it's better than such mixing: code, data, code,
316data, ...).
317
318
319Filters
320-------
321You can increase the compression ratio for some data types, using
322special filters before compressing. For example, it's possible to
323increase the compression ratio on 5-10% for code for those CPU ISAs:
324x86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.
325
326You can find C source code of such filters in C/Bra*.* files
327
328You can check the compression ratio gain of these filters with such
3297-Zip commands (example for ARM code):
330No filter:
331  7z a a1.7z a.bin -m0=lzma
332
333With filter for little-endian ARM code:
334  7z a a2.7z a.bin -m0=arm -m1=lzma
335
336It works in such manner:
337Compressing    = Filter_encoding + LZMA_encoding
338Decompressing  = LZMA_decoding + Filter_decoding
339
340Compressing and decompressing speed of such filters is very high,
341so it will not increase decompressing time too much.
342Moreover, it reduces decompression time for LZMA_decoding,
343since compression ratio with filtering is higher.
344
345These filters convert CALL (calling procedure) instructions
346from relative offsets to absolute addresses, so such data becomes more
347compressible.
348
349For some ISAs (for example, for MIPS) it's impossible to get gain from such filter.
350
351
352
353---
354
355http://www.7-zip.org
356http://www.7-zip.org/sdk.html
357http://www.7-zip.org/support.html
358