other-licenses/7zstub/src/DOC/lzma.txt

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial