blob: 5f1a0c994c44d60fc2930c99719c60a1cfe034cd [file] [log] [blame]
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +02001LZMA SDK 4.57
2-------------
3
4LZMA SDK Copyright (C) 1999-2007 Igor Pavlov
5
6LZMA SDK provides the documentation, samples, header files, libraries,
7and tools you need to develop applications that use LZMA compression.
8
9LZMA is default and general compression method of 7z format
10in 7-Zip compression program (www.7-zip.org). LZMA provides high
11compression ratio and very fast decompression.
12
13LZMA is an improved version of famous LZ77 compression algorithm.
14It was improved in way of maximum increasing of compression ratio,
15keeping high decompression speed and low memory requirements for
16decompressing.
17
18
19
20LICENSE
21-------
22
23LZMA SDK is available under any of the following licenses:
24
251) GNU Lesser General Public License (GNU LGPL)
262) Common Public License (CPL)
273) Simplified license for unmodified code (read SPECIAL EXCEPTION)
284) Proprietary license
29
30It means that you can select one of these four options and follow rules of that license.
31
32
331,2) GNU LGPL and CPL licenses are pretty similar and both these
34licenses are classified as
35 - "Free software licenses" at http://www.gnu.org/
36 - "OSI-approved" at http://www.opensource.org/
37
38
393) SPECIAL EXCEPTION
40
41Igor Pavlov, as the author of this code, expressly permits you
42to statically or dynamically link your code (or bind by name)
43to the files from LZMA SDK without subjecting your linked
44code to the terms of the CPL or GNU LGPL.
45Any modifications or additions to files from LZMA SDK, however,
46are subject to the GNU LGPL or CPL terms.
47
48SPECIAL EXCEPTION allows you to use LZMA SDK in applications with closed code,
49while you keep LZMA SDK code unmodified.
50
51
52SPECIAL EXCEPTION #2: Igor Pavlov, as the author of this code, expressly permits
53you to use this code under the same terms and conditions contained in the License
54Agreement you have for any previous version of LZMA SDK developed by Igor Pavlov.
55
56SPECIAL EXCEPTION #2 allows owners of proprietary licenses to use latest version
57of LZMA SDK as update for previous versions.
58
59
60SPECIAL EXCEPTION #3: Igor Pavlov, as the author of this code, expressly permits
61you to use code of the following files:
62BranchTypes.h, LzmaTypes.h, LzmaTest.c, LzmaStateTest.c, LzmaAlone.cpp,
63LzmaAlone.cs, LzmaAlone.java
64as public domain code.
65
66
674) Proprietary license
68
69LZMA SDK also can be available under a proprietary license which
70can include:
71
721) Right to modify code without subjecting modified code to the
73terms of the CPL or GNU LGPL
742) Technical support for code
75
76To request such proprietary license or any additional consultations,
77send email message from that page:
78http://www.7-zip.org/support.html
79
80
81You should have received a copy of the GNU Lesser General Public
82License along with this library; if not, write to the Free Software
83Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
84
85You should have received a copy of the Common Public License
86along with this library.
87
88
89LZMA SDK Contents
90-----------------
91
92LZMA SDK includes:
93
94 - C++ source code of LZMA compressing and decompressing
95 - ANSI-C compatible source code for LZMA decompressing
96 - C# source code for LZMA compressing and decompressing
97 - Java source code for LZMA compressing and decompressing
98 - Compiled file->file LZMA compressing/decompressing program for Windows system
99
100ANSI-C LZMA decompression code was ported from original C++ sources to C.
101Also it was simplified and optimized for code size.
102But it is fully compatible with LZMA from 7-Zip.
103
104
105UNIX/Linux version
106------------------
107To compile C++ version of file->file LZMA, go to directory
108C/7zip/Compress/LZMA_Alone
109and type "make" or "make clean all" to recompile all.
110
111In some UNIX/Linux versions you must compile LZMA with static libraries.
112To compile with static libraries, change string in makefile
113LIB = -lm
114to string
115LIB = -lm -static
116
117
118Files
119---------------------
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200120C - C source code
121CPP - CPP source code
122CS - C# source code
123Java - Java source code
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200124lzma.txt - LZMA SDK description (this file)
1257zFormat.txt - 7z Format description
1267zC.txt - 7z ANSI-C Decoder description (this file)
127methods.txt - Compression method IDs for .7z
128LGPL.txt - GNU Lesser General Public License
129CPL.html - Common Public License
130lzma.exe - Compiled file->file LZMA encoder/decoder for Windows
131history.txt - history of the LZMA SDK
132
133
134Source code structure
135---------------------
136
137C - C files
138 Compress - files related to compression/decompression
139 Lz - files related to LZ (Lempel-Ziv) compression algorithm
140 Lzma - ANSI-C compatible LZMA decompressor
141
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200142 LzmaDecode.h - interface for LZMA decoding on ANSI-C
143 LzmaDecode.c - LZMA decoding on ANSI-C (new fastest version)
144 LzmaDecodeSize.c - LZMA decoding on ANSI-C (old size-optimized version)
145 LzmaTest.c - test application that decodes LZMA encoded file
146 LzmaTypes.h - basic types for LZMA Decoder
147 LzmaStateDecode.h - interface for LZMA decoding (State version)
148 LzmaStateDecode.c - LZMA decoding on ANSI-C (State version)
149 LzmaStateTest.c - test application (State version)
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200150
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200151 Branch - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200152
153 Archive - files related to archiving
154 7z_C - 7z ANSI-C Decoder
155
156
157CPP -- CPP files
158
159 Common - common files for C++ projects
160 Windows - common files for Windows related code
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200161 7zip - files related to 7-Zip Project
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200162
163 Common - common files for 7-Zip
164
165 Compress - files related to compression/decompression
166
167 LZ - files related to LZ (Lempel-Ziv) compression algorithm
168
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200169 Copy - Copy coder
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200170 RangeCoder - Range Coder (special code of compression/decompression)
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200171 LZMA - LZMA compression/decompression on C++
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200172 LZMA_Alone - file->file LZMA compression/decompression
173
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200174 Branch - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200175
176 Archive - files related to archiving
177
178 Common - common files for archive handling
179 7z - 7z C++ Encoder/Decoder
180
181 Bundles - Modules that are bundles of other modules
182
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200183 Alone7z - 7zr.exe: Standalone version of 7z.exe that supports only 7z/LZMA/BCJ/BCJ2
184 Format7zR - 7zr.dll: Reduced version of 7za.dll: extracting/compressing to 7z/LZMA/BCJ/BCJ2
185 Format7zExtractR - 7zxr.dll: Reduced version of 7zxa.dll: extracting from 7z/LZMA/BCJ/BCJ2.
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200186
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200187 UI - User Interface files
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200188
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200189 Client7z - Test application for 7za.dll, 7zr.dll, 7zxr.dll
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200190 Common - Common UI files
191 Console - Code for console archiver
192
193
194
195CS - C# files
196 7zip
197 Common - some common files for 7-Zip
198 Compress - files related to compression/decompression
199 LZ - files related to LZ (Lempel-Ziv) compression algorithm
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200200 LZMA - LZMA compression/decompression
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200201 LzmaAlone - file->file LZMA compression/decompression
202 RangeCoder - Range Coder (special code of compression/decompression)
203
204Java - Java files
205 SevenZip
206 Compression - files related to compression/decompression
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200207 LZ - files related to LZ (Lempel-Ziv) compression algorithm
208 LZMA - LZMA compression/decompression
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200209 RangeCoder - Range Coder (special code of compression/decompression)
210
211C/C++ source code of LZMA SDK is part of 7-Zip project.
212
213You can find ANSI-C LZMA decompressing code at folder
214 C/7zip/Compress/Lzma
2157-Zip doesn't use that ANSI-C LZMA code and that code was developed
216specially for this SDK. And files from C/7zip/Compress/Lzma do not need
217files from other directories of SDK for compiling.
218
2197-Zip source code can be downloaded from 7-Zip's SourceForge page:
220
221 http://sourceforge.net/projects/sevenzip/
222
223
224LZMA features
225-------------
226 - Variable dictionary size (up to 1 GB)
227 - Estimated compressing speed: about 1 MB/s on 1 GHz CPU
228 - Estimated decompressing speed:
229 - 8-12 MB/s on 1 GHz Intel Pentium 3 or AMD Athlon
230 - 500-1000 KB/s on 100 MHz ARM, MIPS, PowerPC or other simple RISC
231 - Small memory requirements for decompressing (8-32 KB + DictionarySize)
232 - Small code size for decompressing: 2-8 KB (depending from
233 speed optimizations)
234
235LZMA decoder uses only integer operations and can be
236implemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions).
237
238Some critical operations that affect to speed of LZMA decompression:
239 1) 32*16 bit integer multiply
240 2) Misspredicted branches (penalty mostly depends from pipeline length)
241 3) 32-bit shift and arithmetic operations
242
243Speed of LZMA decompressing mostly depends from CPU speed.
244Memory speed has no big meaning. But if your CPU has small data cache,
245overall weight of memory speed will slightly increase.
246
247
248How To Use
249----------
250
251Using LZMA encoder/decoder executable
252--------------------------------------
253
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200254Usage: LZMA <e|d> inputFile outputFile [<switches>...]
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200255
256 e: encode file
257
258 d: decode file
259
260 b: Benchmark. There are two tests: compressing and decompressing
261 with LZMA method. Benchmark shows rating in MIPS (million
262 instructions per second). Rating value is calculated from
263 measured speed and it is normalized with AMD Athlon 64 X2 CPU
264 results. Also Benchmark checks possible hardware errors (RAM
265 errors in most cases). Benchmark uses these settings:
266 (-a1, -d21, -fb32, -mfbt4). You can change only -d. Also you
267 can change number of iterations. Example for 30 iterations:
268 LZMA b 30
269 Default number of iterations is 10.
270
271<Switches>
272
273
274 -a{N}: set compression mode 0 = fast, 1 = normal
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200275 default: 1 (normal)
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200276
277 d{N}: Sets Dictionary size - [0, 30], default: 23 (8MB)
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200278 The maximum value for dictionary size is 1 GB = 2^30 bytes.
279 Dictionary size is calculated as DictionarySize = 2^N bytes.
280 For decompressing file compressed by LZMA method with dictionary
281 size D = 2^N you need about D bytes of memory (RAM).
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200282
283 -fb{N}: set number of fast bytes - [5, 273], default: 128
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200284 Usually big number gives a little bit better compression ratio
285 and slower compression process.
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200286
287 -lc{N}: set number of literal context bits - [0, 8], default: 3
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200288 Sometimes lc=4 gives gain for big files.
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200289
290 -lp{N}: set number of literal pos bits - [0, 4], default: 0
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200291 lp switch is intended for periodical data when period is
292 equal 2^N. For example, for 32-bit (4 bytes)
293 periodical data you can use lp=2. Often it's better to set lc0,
294 if you change lp switch.
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200295
296 -pb{N}: set number of pos bits - [0, 4], default: 2
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200297 pb switch is intended for periodical data
298 when period is equal 2^N.
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200299
300 -mf{MF_ID}: set Match Finder. Default: bt4.
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200301 Algorithms from hc* group doesn't provide good compression
302 ratio, but they often works pretty fast in combination with
303 fast mode (-a0).
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200304
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200305 Memory requirements depend from dictionary size
306 (parameter "d" in table below).
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200307
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200308 MF_ID Memory Description
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200309
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200310 bt2 d * 9.5 + 4MB Binary Tree with 2 bytes hashing.
311 bt3 d * 11.5 + 4MB Binary Tree with 3 bytes hashing.
312 bt4 d * 11.5 + 4MB Binary Tree with 4 bytes hashing.
313 hc4 d * 7.5 + 4MB Hash Chain with 4 bytes hashing.
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200314
315 -eos: write End Of Stream marker. By default LZMA doesn't write
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200316 eos marker, since LZMA decoder knows uncompressed size
317 stored in .lzma file header.
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200318
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200319 -si: Read data from stdin (it will write End Of Stream marker).
320 -so: Write data to stdout
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200321
322
323Examples:
324
3251) LZMA e file.bin file.lzma -d16 -lc0
326
327compresses file.bin to file.lzma with 64 KB dictionary (2^16=64K)
328and 0 literal context bits. -lc0 allows to reduce memory requirements
329for decompression.
330
331
3322) LZMA e file.bin file.lzma -lc0 -lp2
333
334compresses file.bin to file.lzma with settings suitable
335for 32-bit periodical data (for example, ARM or MIPS code).
336
3373) LZMA d file.lzma file.bin
338
339decompresses file.lzma to file.bin.
340
341
342Compression ratio hints
343-----------------------
344
345Recommendations
346---------------
347
348To increase compression ratio for LZMA compressing it's desirable
349to have aligned data (if it's possible) and also it's desirable to locate
350data in such order, where code is grouped in one place and data is
351grouped in other place (it's better than such mixing: code, data, code,
352data, ...).
353
354
355Using Filters
356-------------
357You can increase compression ratio for some data types, using
358special filters before compressing. For example, it's possible to
359increase compression ratio on 5-10% for code for those CPU ISAs:
360x86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC.
361
362You can find C/C++ source code of such filters in folder "7zip/Compress/Branch"
363
364You can check compression ratio gain of these filters with such
3657-Zip commands (example for ARM code):
366No filter:
367 7z a a1.7z a.bin -m0=lzma
368
369With filter for little-endian ARM code:
370 7z a a2.7z a.bin -m0=bc_arm -m1=lzma
371
372With filter for big-endian ARM code (using additional Swap4 filter):
373 7z a a3.7z a.bin -m0=swap4 -m1=bc_arm -m2=lzma
374
375It works in such manner:
376Compressing = Filter_encoding + LZMA_encoding
377Decompressing = LZMA_decoding + Filter_decoding
378
379Compressing and decompressing speed of such filters is very high,
380so it will not increase decompressing time too much.
381Moreover, it reduces decompression time for LZMA_decoding,
382since compression ratio with filtering is higher.
383
384These filters convert CALL (calling procedure) instructions
385from relative offsets to absolute addresses, so such data becomes more
386compressible. Source code of these CALL filters is pretty simple
387(about 20 lines of C++), so you can convert it from C++ version yourself.
388
389For some ISAs (for example, for MIPS) it's impossible to get gain from such filter.
390
391
392LZMA compressed file format
393---------------------------
394Offset Size Description
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200395 0 1 Special LZMA properties for compressed data
396 1 4 Dictionary size (little endian)
397 5 8 Uncompressed size (little endian). -1 means unknown size
398 13 Compressed data
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200399
400
401ANSI-C LZMA Decoder
402~~~~~~~~~~~~~~~~~~~
403
404To compile ANSI-C LZMA Decoder you can use one of the following files sets:
4051) LzmaDecode.h + LzmaDecode.c + LzmaTest.c (fastest version)
4062) LzmaDecode.h + LzmaDecodeSize.c + LzmaTest.c (old size-optimized version)
4073) LzmaStateDecode.h + LzmaStateDecode.c + LzmaStateTest.c (zlib-like interface)
408
409
410Memory requirements for LZMA decoding
411-------------------------------------
412
413LZMA decoder doesn't allocate memory itself, so you must
414allocate memory and send it to LZMA.
415
416Stack usage of LZMA decoding function for local variables is not
417larger than 200 bytes.
418
419How To decompress data
420----------------------
421
422LZMA Decoder (ANSI-C version) now supports 5 interfaces:
4231) Single-call Decompressing
4242) Single-call Decompressing with input stream callback
4253) Multi-call Decompressing with output buffer
4264) Multi-call Decompressing with input callback and output buffer
4275) Multi-call State Decompressing (zlib-like interface)
428
429Variant-5 is similar to Variant-4, but Variant-5 doesn't use callback functions.
430
431Decompressing steps
432-------------------
433
4341) read LZMA properties (5 bytes):
435 unsigned char properties[LZMA_PROPERTIES_SIZE];
436
4372) read uncompressed size (8 bytes, little-endian)
438
4393) Decode properties:
440
441 CLzmaDecoderState state; /* it's 24-140 bytes structure, if int is 32-bit */
442
443 if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)
444 return PrintError(rs, "Incorrect stream properties");
445
4464) Allocate memory block for internal Structures:
447
448 state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));
449 if (state.Probs == 0)
450 return PrintError(rs, kCantAllocateMessage);
451
452 LZMA decoder uses array of CProb variables as internal structure.
453 By default, CProb is unsigned_short. But you can define _LZMA_PROB32 to make
454 it unsigned_int. It can increase speed on some 32-bit CPUs, but memory
455 usage will be doubled in that case.
456
457
4585) Main Decompressing
459
460You must use one of the following interfaces:
461
4625.1 Single-call Decompressing
463-----------------------------
464When to use: RAM->RAM decompressing
465Compile files: LzmaDecode.h, LzmaDecode.c
466Compile defines: no defines
467Memory Requirements:
468 - Input buffer: compressed size
469 - Output buffer: uncompressed size
470 - LZMA Internal Structures (~16 KB for default settings)
471
472Interface:
473 int res = LzmaDecode(&state,
474 inStream, compressedSize, &inProcessed,
475 outStream, outSize, &outProcessed);
476
477
4785.2 Single-call Decompressing with input stream callback
479--------------------------------------------------------
480When to use: File->RAM or Flash->RAM decompressing.
481Compile files: LzmaDecode.h, LzmaDecode.c
482Compile defines: _LZMA_IN_CB
483Memory Requirements:
484 - Buffer for input stream: any size (for example, 16 KB)
485 - Output buffer: uncompressed size
486 - LZMA Internal Structures (~16 KB for default settings)
487
488Interface:
489 typedef struct _CBuffer
490 {
491 ILzmaInCallback InCallback;
492 FILE *File;
493 unsigned char Buffer[kInBufferSize];
494 } CBuffer;
495
496 int LzmaReadCompressed(void *object, const unsigned char **buffer, SizeT *size)
497 {
498 CBuffer *bo = (CBuffer *)object;
499 *buffer = bo->Buffer;
500 *size = MyReadFile(bo->File, bo->Buffer, kInBufferSize);
501 return LZMA_RESULT_OK;
502 }
503
504 CBuffer g_InBuffer;
505
506 g_InBuffer.File = inFile;
507 g_InBuffer.InCallback.Read = LzmaReadCompressed;
508 int res = LzmaDecode(&state,
509 &g_InBuffer.InCallback,
510 outStream, outSize, &outProcessed);
511
512
5135.3 Multi-call decompressing with output buffer
514-----------------------------------------------
515When to use: RAM->File decompressing
516Compile files: LzmaDecode.h, LzmaDecode.c
517Compile defines: _LZMA_OUT_READ
518Memory Requirements:
519 - Input buffer: compressed size
520 - Buffer for output stream: any size (for example, 16 KB)
521 - LZMA Internal Structures (~16 KB for default settings)
522 - LZMA dictionary (dictionary size is encoded in stream properties)
523
524Interface:
525
526 state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);
527
528 LzmaDecoderInit(&state);
529 do
530 {
531 LzmaDecode(&state,
532 inBuffer, inAvail, &inProcessed,
533 g_OutBuffer, outAvail, &outProcessed);
534 inAvail -= inProcessed;
535 inBuffer += inProcessed;
536 }
537 while you need more bytes
538
539 see LzmaTest.c for more details.
540
541
5425.4 Multi-call decompressing with input callback and output buffer
543------------------------------------------------------------------
544When to use: File->File decompressing
545Compile files: LzmaDecode.h, LzmaDecode.c
546Compile defines: _LZMA_IN_CB, _LZMA_OUT_READ
547Memory Requirements:
548 - Buffer for input stream: any size (for example, 16 KB)
549 - Buffer for output stream: any size (for example, 16 KB)
550 - LZMA Internal Structures (~16 KB for default settings)
551 - LZMA dictionary (dictionary size is encoded in stream properties)
552
553Interface:
554
555 state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);
556
557 LzmaDecoderInit(&state);
558 do
559 {
560 LzmaDecode(&state,
561 &bo.InCallback,
562 g_OutBuffer, outAvail, &outProcessed);
563 }
564 while you need more bytes
565
566 see LzmaTest.c for more details:
567
568
5695.5 Multi-call State Decompressing (zlib-like interface)
570------------------------------------------------------------------
571When to use: file->file decompressing
572Compile files: LzmaStateDecode.h, LzmaStateDecode.c
573Compile defines:
574Memory Requirements:
575 - Buffer for input stream: any size (for example, 16 KB)
576 - Buffer for output stream: any size (for example, 16 KB)
577 - LZMA Internal Structures (~16 KB for default settings)
578 - LZMA dictionary (dictionary size is encoded in stream properties)
579
580Interface:
581
582 state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);
583
584
585 LzmaDecoderInit(&state);
586 do
587 {
588 res = LzmaDecode(&state,
589 inBuffer, inAvail, &inProcessed,
590 g_OutBuffer, outAvail, &outProcessed,
591 finishDecoding);
592 inAvail -= inProcessed;
593 inBuffer += inProcessed;
594 }
595 while you need more bytes
596
597 see LzmaStateTest.c for more details:
598
599
6006) Free all allocated blocks
601
602
603Note
604----
605LzmaDecodeSize.c is size-optimized version of LzmaDecode.c.
606But compiled code of LzmaDecodeSize.c can be larger than
607compiled code of LzmaDecode.c. So it's better to use
608LzmaDecode.c in most cases.
609
610
611EXIT codes
612-----------
613
614LZMA decoder can return one of the following codes:
615
616#define LZMA_RESULT_OK 0
617#define LZMA_RESULT_DATA_ERROR 1
618
619If you use callback function for input data and you return some
620error code, LZMA Decoder also returns that code.
621
622
623
624LZMA Defines
625------------
626
627_LZMA_IN_CB - Use callback for input data
628
629_LZMA_OUT_READ - Use read function for output data
630
631_LZMA_LOC_OPT - Enable local speed optimizations inside code.
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200632 _LZMA_LOC_OPT is only for LzmaDecodeSize.c (size-optimized version).
633 _LZMA_LOC_OPT doesn't affect LzmaDecode.c (speed-optimized version)
634 and LzmaStateDecode.c
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200635
636_LZMA_PROB32 - It can increase speed on some 32-bit CPUs,
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200637 but memory usage will be doubled in that case
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200638
639_LZMA_UINT32_IS_ULONG - Define it if int is 16-bit on your compiler
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200640 and long is 32-bit.
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200641
642_LZMA_SYSTEM_SIZE_T - Define it if you want to use system's size_t.
Wolfgang Denk9dbbd7b2008-09-13 02:23:05 +0200643 You can use it to enable 64-bit sizes supporting
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200644
645
646
647C++ LZMA Encoder/Decoder
648~~~~~~~~~~~~~~~~~~~~~~~~
649C++ LZMA code use COM-like interfaces. So if you want to use it,
650you can study basics of COM/OLE.
651
652By default, LZMA Encoder contains all Match Finders.
653But for compressing it's enough to have just one of them.
654So for reducing size of compressing code you can define:
655 #define COMPRESS_MF_BT
656 #define COMPRESS_MF_BT4
657and it will use only bt4 match finder.
658
659
660---
661
662http://www.7-zip.org
663http://www.7-zip.org/support.html