• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1LZMA SDK 23.01
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------------------
65There are several otpions to compile 7-Zip with different compilers: gcc and clang.
66Also 7-Zip code contains two versions for some critical parts of code: in C and in Assembeler.
67So if you compile the version with Assembeler code, you will get faster 7-Zip binary.
68
697-Zip's assembler code uses the following syntax for different platforms:
70
711) x86 and x86-64 (AMD64): MASM syntax.
72   There are 2 programs that supports MASM syntax in Linux.
73'    'Asmc Macro Assembler and JWasm. But JWasm now doesn't support some
74      cpu instructions used in 7-Zip.
75   So you must install Asmc Macro Assembler in Linux, if you want to compile fastest version
76   of 7-Zip  x86 and x86-64:
77     https://github.com/nidud/asmc
78
792) arm64: GNU assembler for ARM64 with preprocessor.
80   That systax of that arm64 assembler code in 7-Zip is supported by GCC and CLANG for ARM64.
81
82There are different binaries that can be compiled from 7-Zip source.
83There are 2 main files in folder for compiling:
84  makefile        - that can be used for compiling Windows version of 7-Zip with nmake command
85  makefile.gcc    - that can be used for compiling Linux/macOS versions of 7-Zip with make command
86
87At first you must change the current folder to folder that contains `makefile.gcc`:
88
89  cd CPP/7zip/Bundles/Alone7z
90
91Then you can compile `makefile.gcc` with the command:
92
93  make -j -f makefile.gcc
94
95Also there are additional "*.mak" files in folder "CPP/7zip/" that can be used to compile
967-Zip binaries with optimized code and optimzing options.
97
98To compile with GCC without assembler:
99  cd CPP/7zip/Bundles/Alone7z
100  make -j -f ../../cmpl_gcc.mak
101
102To compile with CLANG without assembler:
103  make -j -f ../../cmpl_clang.mak
104
105To compile 7-Zip for x86-64 with asmc assembler:
106  make -j -f ../../cmpl_gcc_x64.mak
107
108To compile 7-Zip for arm64 with assembler:
109  make -j -f ../../cmpl_gcc_arm64.mak
110
111To compile 7-Zip for arm64 for macOS:
112  make -j -f ../../cmpl_mac_arm64.mak
113
114Also you can change some compiler options in the mak files:
115  cmpl_gcc.mak
116  var_gcc.mak
117  warn_gcc.mak
118
119
120
121Also you can use p7zip (port of 7-Zip for POSIX systems like Unix or Linux):
122
123  http://p7zip.sourceforge.net/
124
125
126Files
127-----
128
129DOC/7zC.txt          - 7z ANSI-C Decoder description
130DOC/7zFormat.txt     - 7z Format description
131DOC/installer.txt    - information about 7-Zip for installers
132DOC/lzma.txt         - LZMA compression description
133DOC/lzma-sdk.txt     - LZMA SDK description (this file)
134DOC/lzma-history.txt - history of LZMA SDK
135DOC/lzma-specification.txt - Specification of LZMA
136DOC/Methods.txt      - Compression method IDs for .7z
137
138bin/installer/   - example script to create installer that uses SFX module,
139
140bin/7zdec.exe    - simplified 7z archive decoder
141bin/7zr.exe      - 7-Zip console program (reduced version)
142bin/x64/7zr.exe  - 7-Zip console program (reduced version) (x64 version)
143bin/lzma.exe     - file->file LZMA encoder/decoder for Windows
144bin/7zS2.sfx     - small SFX module for installers (GUI version)
145bin/7zS2con.sfx  - small SFX module for installers (Console version)
146bin/7zSD.sfx     - SFX module for installers.
147
148
1497zDec.exe
150---------
1517zDec.exe is simplified 7z archive decoder.
152It supports only LZMA, LZMA2, and PPMd methods.
1537zDec decodes whole solid block from 7z archive to RAM.
154The RAM consumption can be high.
155
156
157
158
159Source code structure
160---------------------
161
162
163Asm/ - asm files (optimized code for CRC calculation and Intel-AES encryption)
164
165C/  - C files (compression / decompression and other)
166  Util/
167    7z       - 7z decoder program (decoding 7z files)
168    Lzma     - LZMA program (file->file LZMA encoder/decoder).
169    LzmaLib  - LZMA library (.DLL for Windows)
170    SfxSetup - small SFX module for installers
171
172CPP/ -- CPP files
173
174  Common  - common files for C++ projects
175  Windows - common files for Windows related code
176
177  7zip    - files related to 7-Zip
178
179    Archive - files related to archiving
180
181      Common   - common files for archive handling
182      7z       - 7z C++ Encoder/Decoder
183
184    Bundles  - Modules that are bundles of other modules (files)
185
186      Alone7z       - 7zr.exe: Standalone 7-Zip console program (reduced version)
187      Format7zExtractR  - 7zxr.dll: Reduced version of 7z DLL: extracting from 7z/LZMA/BCJ/BCJ2.
188      Format7zR         - 7zr.dll:  Reduced version of 7z DLL: extracting/compressing to 7z/LZMA/BCJ/BCJ2
189      LzmaCon       - lzma.exe: LZMA compression/decompression
190      LzmaSpec      - example code for LZMA Specification
191      SFXCon        - 7zCon.sfx: Console 7z SFX module
192      SFXSetup      - 7zS.sfx: 7z SFX module for installers
193      SFXWin        - 7z.sfx: GUI 7z SFX module
194
195    Common   - common files for 7-Zip
196
197    Compress - files for compression/decompression
198
199    Crypto   - files for encryption / decompression
200
201    UI       - User Interface files
202
203      Client7z - Test application for 7za.dll, 7zr.dll, 7zxr.dll
204      Common   - Common UI files
205      Console  - Code for console program (7z.exe)
206      Explorer    - Some code from 7-Zip Shell extension
207      FileManager - Some GUI code from 7-Zip File Manager
208      GUI         - Some GUI code from 7-Zip
209
210
211CS/ - C# files
212  7zip
213    Common   - some common files for 7-Zip
214    Compress - files related to compression/decompression
215      LZ     - files related to LZ (Lempel-Ziv) compression algorithm
216      LZMA         - LZMA compression/decompression
217      LzmaAlone    - file->file LZMA compression/decompression
218      RangeCoder   - Range Coder (special code of compression/decompression)
219
220Java/  - Java files
221  SevenZip
222    Compression    - files related to compression/decompression
223      LZ           - files related to LZ (Lempel-Ziv) compression algorithm
224      LZMA         - LZMA compression/decompression
225      RangeCoder   - Range Coder (special code of compression/decompression)
226
227
228Note:
229  Asm / C / C++ source code of LZMA SDK is part of 7-Zip's source code.
230  7-Zip's source code can be downloaded from 7-Zip's SourceForge page:
231
232  http://sourceforge.net/projects/sevenzip/
233
234
235
236LZMA features
237-------------
238  - Variable dictionary size (up to 1 GB)
239  - Estimated compressing speed: about 2 MB/s on 2 GHz CPU
240  - Estimated decompressing speed:
241      - 20-30 MB/s on modern 2 GHz cpu
242      - 1-2 MB/s on 200 MHz simple RISC cpu: (ARM, MIPS, PowerPC)
243  - Small memory requirements for decompressing (16 KB + DictionarySize)
244  - Small code size for decompressing: 5-8 KB
245
246LZMA decoder uses only integer operations and can be
247implemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).
248
249Some critical operations that affect the speed of LZMA decompression:
250  1) 32*16 bit integer multiply
251  2) Mispredicted branches (penalty mostly depends from pipeline length)
252  3) 32-bit shift and arithmetic operations
253
254The speed of LZMA decompressing mostly depends from CPU speed.
255Memory speed has no big meaning. But if your CPU has small data cache,
256overall weight of memory speed will slightly increase.
257
258
259How To Use
260----------
261
262Using LZMA encoder/decoder executable
263--------------------------------------
264
265Usage:  LZMA <e|d> inputFile outputFile [<switches>...]
266
267  e: encode file
268
269  d: decode file
270
271  b: Benchmark. There are two tests: compressing and decompressing
272     with LZMA method. Benchmark shows rating in MIPS (million
273     instructions per second). Rating value is calculated from
274     measured speed and it is normalized with Intel's Core 2 results.
275     Also Benchmark checks possible hardware errors (RAM
276     errors in most cases). Benchmark uses these settings:
277     (-a1, -d21, -fb32, -mfbt4). You can change only -d parameter.
278     Also you can change the number of iterations. Example for 30 iterations:
279       LZMA b 30
280     Default number of iterations is 10.
281
282<Switches>
283
284
285  -a{N}:  set compression mode 0 = fast, 1 = normal
286          default: 1 (normal)
287
288  d{N}:   Sets Dictionary size - [0, 30], default: 23 (8MB)
289          The maximum value for dictionary size is 1 GB = 2^30 bytes.
290          Dictionary size is calculated as DictionarySize = 2^N bytes.
291          For decompressing file compressed by LZMA method with dictionary
292          size D = 2^N you need about D bytes of memory (RAM).
293
294  -fb{N}: set number of fast bytes - [5, 273], default: 128
295          Usually big number gives a little bit better compression ratio
296          and slower compression process.
297
298  -lc{N}: set number of literal context bits - [0, 8], default: 3
299          Sometimes lc=4 gives gain for big files.
300
301  -lp{N}: set number of literal pos bits - [0, 4], default: 0
302          lp switch is intended for periodical data when period is
303          equal 2^N. For example, for 32-bit (4 bytes)
304          periodical data you can use lp=2. Often it's better to set lc0,
305          if you change lp switch.
306
307  -pb{N}: set number of pos bits - [0, 4], default: 2
308          pb switch is intended for periodical data
309          when period is equal 2^N.
310
311  -mf{MF_ID}: set Match Finder. Default: bt4.
312              Algorithms from hc* group doesn't provide good compression
313              ratio, but they often works pretty fast in combination with
314              fast mode (-a0).
315
316              Memory requirements depend from dictionary size
317              (parameter "d" in table below).
318
319               MF_ID     Memory                   Description
320
321                bt2    d *  9.5 + 4MB  Binary Tree with 2 bytes hashing.
322                bt3    d * 11.5 + 4MB  Binary Tree with 3 bytes hashing.
323                bt4    d * 11.5 + 4MB  Binary Tree with 4 bytes hashing.
324                hc4    d *  7.5 + 4MB  Hash Chain with 4 bytes hashing.
325
326  -eos:   write End Of Stream marker. By default LZMA doesn't write
327          eos marker, since LZMA decoder knows uncompressed size
328          stored in .lzma file header.
329
330  -si:    Read data from stdin (it will write End Of Stream marker).
331  -so:    Write data to stdout
332
333
334Examples:
335
3361) LZMA e file.bin file.lzma -d16 -lc0
337
338compresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)
339and 0 literal context bits. -lc0 allows to reduce memory requirements
340for decompression.
341
342
3432) LZMA e file.bin file.lzma -lc0 -lp2
344
345compresses file.bin to file.lzma with settings suitable
346for 32-bit periodical data (for example, ARM or MIPS code).
347
3483) LZMA d file.lzma file.bin
349
350decompresses file.lzma to file.bin.
351
352
353Compression ratio hints
354-----------------------
355
356Recommendations
357---------------
358
359To increase the compression ratio for LZMA compressing it's desirable
360to have aligned data (if it's possible) and also it's desirable to locate
361data in such order, where code is grouped in one place and data is
362grouped in other place (it's better than such mixing: code, data, code,
363data, ...).
364
365
366Filters
367-------
368You can increase the compression ratio for some data types, using
369special filters before compressing. For example, it's possible to
370increase the compression ratio on 5-10% for code for those CPU ISAs:
371x86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.
372
373You can find C source code of such filters in C/Bra*.* files
374
375You can check the compression ratio gain of these filters with such
3767-Zip commands (example for ARM code):
377No filter:
378  7z a a1.7z a.bin -m0=lzma
379
380With filter for little-endian ARM code:
381  7z a a2.7z a.bin -m0=arm -m1=lzma
382
383It works in such manner:
384Compressing    = Filter_encoding + LZMA_encoding
385Decompressing  = LZMA_decoding + Filter_decoding
386
387Compressing and decompressing speed of such filters is very high,
388so it will not increase decompressing time too much.
389Moreover, it reduces decompression time for LZMA_decoding,
390since compression ratio with filtering is higher.
391
392These filters convert CALL (calling procedure) instructions
393from relative offsets to absolute addresses, so such data becomes more
394compressible.
395
396For some ISAs (for example, for MIPS) it's impossible to get gain from such filter.
397
398
399
400---
401
402http://www.7-zip.org
403http://www.7-zip.org/sdk.html
404http://www.7-zip.org/support.html
405