Blame view
lib/lzma/lzma.txt
19.2 KB
5fe8380db lzma: update to l... |
1 |
LZMA SDK 9.20 |
fc9c1727b Add support for L... |
2 |
------------- |
fc9c1727b Add support for L... |
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
LZMA SDK provides the documentation, samples, header files, libraries, and tools you need to develop applications that use LZMA compression. LZMA is default and general compression method of 7z format in 7-Zip compression program (www.7-zip.org). LZMA provides high compression ratio and very fast decompression. LZMA is an improved version of famous LZ77 compression algorithm. It was improved in way of maximum increasing of compression ratio, keeping high decompression speed and low memory requirements for decompressing. LICENSE ------- |
caf72ff32 Refresh LZMA-lib ... |
19 |
LZMA SDK is written and placed in the public domain by Igor Pavlov. |
fc9c1727b Add support for L... |
20 |
|
5fe8380db lzma: update to l... |
21 22 23 |
Some code in LZMA SDK is based on public domain code from another developers: 1) PPMd var.H (2001): Dmitry Shkarin 2) SHA-256: Wei Dai (Crypto++ library) |
fc9c1727b Add support for L... |
24 25 26 27 28 |
LZMA SDK Contents ----------------- LZMA SDK includes: |
caf72ff32 Refresh LZMA-lib ... |
29 |
- ANSI-C/C++/C#/Java source code for LZMA compressing and decompressing |
fc9c1727b Add support for L... |
30 |
- Compiled file->file LZMA compressing/decompressing program for Windows system |
fc9c1727b Add support for L... |
31 32 33 |
UNIX/Linux version ------------------ |
caf72ff32 Refresh LZMA-lib ... |
34 |
To compile C++ version of file->file LZMA encoding, go to directory |
5fe8380db lzma: update to l... |
35 |
CPP/7zip/Bundles/LzmaCon |
caf72ff32 Refresh LZMA-lib ... |
36 37 |
and call make to recompile it: make -f makefile.gcc clean all |
fc9c1727b Add support for L... |
38 39 |
In some UNIX/Linux versions you must compile LZMA with static libraries. |
caf72ff32 Refresh LZMA-lib ... |
40 |
To compile with static libraries, you can use |
fc9c1727b Add support for L... |
41 42 43 44 45 |
LIB = -lm -static Files --------------------- |
caf72ff32 Refresh LZMA-lib ... |
46 |
lzma.txt - LZMA SDK description (this file) |
fc9c1727b Add support for L... |
47 |
7zFormat.txt - 7z Format description |
caf72ff32 Refresh LZMA-lib ... |
48 |
7zC.txt - 7z ANSI-C Decoder description |
fc9c1727b Add support for L... |
49 |
methods.txt - Compression method IDs for .7z |
caf72ff32 Refresh LZMA-lib ... |
50 |
lzma.exe - Compiled file->file LZMA encoder/decoder for Windows |
5fe8380db lzma: update to l... |
51 |
7zr.exe - 7-Zip with 7z/lzma/xz support. |
caf72ff32 Refresh LZMA-lib ... |
52 |
history.txt - history of the LZMA SDK |
fc9c1727b Add support for L... |
53 54 55 56 |
Source code structure --------------------- |
caf72ff32 Refresh LZMA-lib ... |
57 58 59 60 61 62 63 64 65 66 67 |
C/ - C files 7zCrc*.* - CRC code Alloc.* - Memory allocation functions Bra*.* - Filters for x86, IA-64, ARM, ARM-Thumb, PowerPC and SPARC code LzFind.* - Match finder for LZ (LZMA) encoders LzFindMt.* - Match finder for LZ (LZMA) encoders for multithreading encoding LzHash.h - Additional file for LZ match finder LzmaDec.* - LZMA decoding LzmaEnc.* - LZMA encoding LzmaLib.* - LZMA Library for DLL calling Types.h - Basic types for another .c files |
5fe8380db lzma: update to l... |
68 |
Threads.* - The code for multithreading. |
fc9c1727b Add support for L... |
69 |
|
caf72ff32 Refresh LZMA-lib ... |
70 |
LzmaLib - LZMA Library (.DLL for Windows) |
fc9c1727b Add support for L... |
71 |
|
caf72ff32 Refresh LZMA-lib ... |
72 |
LzmaUtil - LZMA Utility (file->file LZMA encoder/decoder). |
fc9c1727b Add support for L... |
73 74 |
Archive - files related to archiving |
caf72ff32 Refresh LZMA-lib ... |
75 |
7z - 7z ANSI-C Decoder |
fc9c1727b Add support for L... |
76 |
|
caf72ff32 Refresh LZMA-lib ... |
77 |
CPP/ -- CPP files |
fc9c1727b Add support for L... |
78 79 80 |
Common - common files for C++ projects Windows - common files for Windows related code |
caf72ff32 Refresh LZMA-lib ... |
81 82 |
7zip - files related to 7-Zip Project |
fc9c1727b Add support for L... |
83 84 85 86 |
Common - common files for 7-Zip Compress - files related to compression/decompression |
fc9c1727b Add support for L... |
87 88 89 90 91 92 |
Archive - files related to archiving Common - common files for archive handling 7z - 7z C++ Encoder/Decoder Bundles - Modules that are bundles of other modules |
caf72ff32 Refresh LZMA-lib ... |
93 |
Alone7z - 7zr.exe: Standalone version of 7z.exe that supports only 7z/LZMA/BCJ/BCJ2 |
5fe8380db lzma: update to l... |
94 |
LzmaCon - lzma.exe: LZMA compression/decompression |
caf72ff32 Refresh LZMA-lib ... |
95 96 |
Format7zR - 7zr.dll: Reduced version of 7za.dll: extracting/compressing to 7z/LZMA/BCJ/BCJ2 Format7zExtractR - 7zxr.dll: Reduced version of 7zxa.dll: extracting from 7z/LZMA/BCJ/BCJ2. |
fc9c1727b Add support for L... |
97 |
|
caf72ff32 Refresh LZMA-lib ... |
98 |
UI - User Interface files |
fc9c1727b Add support for L... |
99 |
|
caf72ff32 Refresh LZMA-lib ... |
100 |
Client7z - Test application for 7za.dll, 7zr.dll, 7zxr.dll |
fc9c1727b Add support for L... |
101 102 |
Common - Common UI files Console - Code for console archiver |
caf72ff32 Refresh LZMA-lib ... |
103 |
CS/ - C# files |
fc9c1727b Add support for L... |
104 105 106 107 |
7zip Common - some common files for 7-Zip Compress - files related to compression/decompression LZ - files related to LZ (Lempel-Ziv) compression algorithm |
caf72ff32 Refresh LZMA-lib ... |
108 |
LZMA - LZMA compression/decompression |
fc9c1727b Add support for L... |
109 110 |
LzmaAlone - file->file LZMA compression/decompression RangeCoder - Range Coder (special code of compression/decompression) |
caf72ff32 Refresh LZMA-lib ... |
111 |
Java/ - Java files |
fc9c1727b Add support for L... |
112 113 |
SevenZip Compression - files related to compression/decompression |
caf72ff32 Refresh LZMA-lib ... |
114 115 |
LZ - files related to LZ (Lempel-Ziv) compression algorithm LZMA - LZMA compression/decompression |
fc9c1727b Add support for L... |
116 |
RangeCoder - Range Coder (special code of compression/decompression) |
fc9c1727b Add support for L... |
117 |
|
caf72ff32 Refresh LZMA-lib ... |
118 |
C/C++ source code of LZMA SDK is part of 7-Zip project. |
fc9c1727b Add support for L... |
119 120 121 |
7-Zip source code can be downloaded from 7-Zip's SourceForge page: http://sourceforge.net/projects/sevenzip/ |
caf72ff32 Refresh LZMA-lib ... |
122 |
|
fc9c1727b Add support for L... |
123 124 125 |
LZMA features ------------- - Variable dictionary size (up to 1 GB) |
caf72ff32 Refresh LZMA-lib ... |
126 |
- Estimated compressing speed: about 2 MB/s on 2 GHz CPU |
fc9c1727b Add support for L... |
127 |
- Estimated decompressing speed: |
caf72ff32 Refresh LZMA-lib ... |
128 129 130 131 |
- 20-30 MB/s on 2 GHz Core 2 or AMD Athlon 64 - 1-2 MB/s on 200 MHz ARM, MIPS, PowerPC or other simple RISC - Small memory requirements for decompressing (16 KB + DictionarySize) - Small code size for decompressing: 5-8 KB |
fc9c1727b Add support for L... |
132 133 134 |
LZMA decoder uses only integer operations and can be implemented in any modern 32-bit CPU (or on 16-bit CPU with some conditions). |
caf72ff32 Refresh LZMA-lib ... |
135 |
Some critical operations that affect the speed of LZMA decompression: |
fc9c1727b Add support for L... |
136 137 138 |
1) 32*16 bit integer multiply 2) Misspredicted branches (penalty mostly depends from pipeline length) 3) 32-bit shift and arithmetic operations |
caf72ff32 Refresh LZMA-lib ... |
139 |
The speed of LZMA decompressing mostly depends from CPU speed. |
fc9c1727b Add support for L... |
140 141 142 143 144 145 146 147 148 |
Memory speed has no big meaning. But if your CPU has small data cache, overall weight of memory speed will slightly increase. How To Use ---------- Using LZMA encoder/decoder executable -------------------------------------- |
caf72ff32 Refresh LZMA-lib ... |
149 |
Usage: LZMA <e|d> inputFile outputFile [<switches>...] |
fc9c1727b Add support for L... |
150 151 152 153 154 155 156 157 |
e: encode file d: decode file b: Benchmark. There are two tests: compressing and decompressing with LZMA method. Benchmark shows rating in MIPS (million instructions per second). Rating value is calculated from |
caf72ff32 Refresh LZMA-lib ... |
158 159 |
measured speed and it is normalized with Intel's Core 2 results. Also Benchmark checks possible hardware errors (RAM |
fc9c1727b Add support for L... |
160 |
errors in most cases). Benchmark uses these settings: |
caf72ff32 Refresh LZMA-lib ... |
161 162 |
(-a1, -d21, -fb32, -mfbt4). You can change only -d parameter. Also you can change the number of iterations. Example for 30 iterations: |
fc9c1727b Add support for L... |
163 164 165 166 167 168 169 |
LZMA b 30 Default number of iterations is 10. <Switches> -a{N}: set compression mode 0 = fast, 1 = normal |
caf72ff32 Refresh LZMA-lib ... |
170 |
default: 1 (normal) |
fc9c1727b Add support for L... |
171 172 |
d{N}: Sets Dictionary size - [0, 30], default: 23 (8MB) |
caf72ff32 Refresh LZMA-lib ... |
173 174 175 176 |
The maximum value for dictionary size is 1 GB = 2^30 bytes. Dictionary size is calculated as DictionarySize = 2^N bytes. For decompressing file compressed by LZMA method with dictionary size D = 2^N you need about D bytes of memory (RAM). |
fc9c1727b Add support for L... |
177 178 |
-fb{N}: set number of fast bytes - [5, 273], default: 128 |
caf72ff32 Refresh LZMA-lib ... |
179 180 |
Usually big number gives a little bit better compression ratio and slower compression process. |
fc9c1727b Add support for L... |
181 182 |
-lc{N}: set number of literal context bits - [0, 8], default: 3 |
caf72ff32 Refresh LZMA-lib ... |
183 |
Sometimes lc=4 gives gain for big files. |
fc9c1727b Add support for L... |
184 185 |
-lp{N}: set number of literal pos bits - [0, 4], default: 0 |
caf72ff32 Refresh LZMA-lib ... |
186 187 188 189 |
lp switch is intended for periodical data when period is equal 2^N. For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's better to set lc0, if you change lp switch. |
fc9c1727b Add support for L... |
190 191 |
-pb{N}: set number of pos bits - [0, 4], default: 2 |
caf72ff32 Refresh LZMA-lib ... |
192 193 |
pb switch is intended for periodical data when period is equal 2^N. |
fc9c1727b Add support for L... |
194 195 |
-mf{MF_ID}: set Match Finder. Default: bt4. |
caf72ff32 Refresh LZMA-lib ... |
196 197 198 |
Algorithms from hc* group doesn't provide good compression ratio, but they often works pretty fast in combination with fast mode (-a0). |
fc9c1727b Add support for L... |
199 |
|
caf72ff32 Refresh LZMA-lib ... |
200 201 |
Memory requirements depend from dictionary size (parameter "d" in table below). |
fc9c1727b Add support for L... |
202 |
|
caf72ff32 Refresh LZMA-lib ... |
203 |
MF_ID Memory Description |
fc9c1727b Add support for L... |
204 |
|
caf72ff32 Refresh LZMA-lib ... |
205 206 207 208 |
bt2 d * 9.5 + 4MB Binary Tree with 2 bytes hashing. bt3 d * 11.5 + 4MB Binary Tree with 3 bytes hashing. bt4 d * 11.5 + 4MB Binary Tree with 4 bytes hashing. hc4 d * 7.5 + 4MB Hash Chain with 4 bytes hashing. |
fc9c1727b Add support for L... |
209 210 |
-eos: write End Of Stream marker. By default LZMA doesn't write |
caf72ff32 Refresh LZMA-lib ... |
211 212 |
eos marker, since LZMA decoder knows uncompressed size stored in .lzma file header. |
fc9c1727b Add support for L... |
213 |
|
caf72ff32 Refresh LZMA-lib ... |
214 215 |
-si: Read data from stdin (it will write End Of Stream marker). -so: Write data to stdout |
fc9c1727b Add support for L... |
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
Examples: 1) LZMA e file.bin file.lzma -d16 -lc0 compresses file.bin to file.lzma with 64 KB dictionary (2^16=64K) and 0 literal context bits. -lc0 allows to reduce memory requirements for decompression. 2) LZMA e file.bin file.lzma -lc0 -lp2 compresses file.bin to file.lzma with settings suitable for 32-bit periodical data (for example, ARM or MIPS code). 3) LZMA d file.lzma file.bin decompresses file.lzma to file.bin. Compression ratio hints ----------------------- Recommendations --------------- |
caf72ff32 Refresh LZMA-lib ... |
242 |
To increase the compression ratio for LZMA compressing it's desirable |
fc9c1727b Add support for L... |
243 244 245 246 |
to have aligned data (if it's possible) and also it's desirable to locate data in such order, where code is grouped in one place and data is grouped in other place (it's better than such mixing: code, data, code, data, ...). |
caf72ff32 Refresh LZMA-lib ... |
247 248 249 |
Filters ------- You can increase the compression ratio for some data types, using |
fc9c1727b Add support for L... |
250 |
special filters before compressing. For example, it's possible to |
caf72ff32 Refresh LZMA-lib ... |
251 |
increase the compression ratio on 5-10% for code for those CPU ISAs: |
fc9c1727b Add support for L... |
252 |
x86, IA-64, ARM, ARM-Thumb, PowerPC, SPARC. |
caf72ff32 Refresh LZMA-lib ... |
253 |
You can find C source code of such filters in C/Bra*.* files |
fc9c1727b Add support for L... |
254 |
|
caf72ff32 Refresh LZMA-lib ... |
255 |
You can check the compression ratio gain of these filters with such |
fc9c1727b Add support for L... |
256 257 258 259 260 |
7-Zip commands (example for ARM code): No filter: 7z a a1.7z a.bin -m0=lzma With filter for little-endian ARM code: |
caf72ff32 Refresh LZMA-lib ... |
261 |
7z a a2.7z a.bin -m0=arm -m1=lzma |
fc9c1727b Add support for L... |
262 263 264 265 266 267 268 269 270 271 272 273 |
It works in such manner: Compressing = Filter_encoding + LZMA_encoding Decompressing = LZMA_decoding + Filter_decoding Compressing and decompressing speed of such filters is very high, so it will not increase decompressing time too much. Moreover, it reduces decompression time for LZMA_decoding, since compression ratio with filtering is higher. These filters convert CALL (calling procedure) instructions from relative offsets to absolute addresses, so such data becomes more |
caf72ff32 Refresh LZMA-lib ... |
274 |
compressible. |
fc9c1727b Add support for L... |
275 276 277 278 279 280 281 |
For some ISAs (for example, for MIPS) it's impossible to get gain from such filter. LZMA compressed file format --------------------------- Offset Size Description |
caf72ff32 Refresh LZMA-lib ... |
282 283 284 285 |
0 1 Special LZMA properties (lc,lp, pb in encoded form) 1 4 Dictionary size (little endian) 5 8 Uncompressed size (little endian). -1 means unknown size 13 Compressed data |
fc9c1727b Add support for L... |
286 287 288 289 |
ANSI-C LZMA Decoder ~~~~~~~~~~~~~~~~~~~ |
caf72ff32 Refresh LZMA-lib ... |
290 291 292 293 294 295 296 |
Please note that interfaces for ANSI-C code were changed in LZMA SDK 4.58. If you want to use old interfaces you can download previous version of LZMA SDK from sourceforge.net site. To use ANSI-C LZMA Decoder you need the following files: 1) LzmaDec.h + LzmaDec.c + Types.h LzmaUtil/LzmaUtil.c is example application that uses these files. |
fc9c1727b Add support for L... |
297 298 299 300 |
Memory requirements for LZMA decoding ------------------------------------- |
fc9c1727b Add support for L... |
301 |
Stack usage of LZMA decoding function for local variables is not |
caf72ff32 Refresh LZMA-lib ... |
302 303 304 305 306 307 |
larger than 200-400 bytes. LZMA Decoder uses dictionary buffer and internal state structure. Internal state structure consumes state_size = (4 + (1.5 << (lc + lp))) KB by default (lc=3, lp=0), state_size = 16 KB. |
fc9c1727b Add support for L... |
308 309 310 |
How To decompress data ---------------------- |
caf72ff32 Refresh LZMA-lib ... |
311 |
LZMA Decoder (ANSI-C version) now supports 2 interfaces: |
fc9c1727b Add support for L... |
312 |
1) Single-call Decompressing |
caf72ff32 Refresh LZMA-lib ... |
313 |
2) Multi-call State Decompressing (zlib-like interface) |
fc9c1727b Add support for L... |
314 |
|
caf72ff32 Refresh LZMA-lib ... |
315 316 317 318 319 |
You must use external allocator: Example: void *SzAlloc(void *p, size_t size) { p = p; return malloc(size); } void SzFree(void *p, void *address) { p = p; free(address); } ISzAlloc alloc = { SzAlloc, SzFree }; |
fc9c1727b Add support for L... |
320 |
|
caf72ff32 Refresh LZMA-lib ... |
321 |
You can use p = p; operator to disable compiler warnings. |
fc9c1727b Add support for L... |
322 |
|
fc9c1727b Add support for L... |
323 |
|
caf72ff32 Refresh LZMA-lib ... |
324 325 |
Single-call Decompressing ------------------------- |
fc9c1727b Add support for L... |
326 |
When to use: RAM->RAM decompressing |
caf72ff32 Refresh LZMA-lib ... |
327 |
Compile files: LzmaDec.h + LzmaDec.c + Types.h |
fc9c1727b Add support for L... |
328 329 330 331 |
Compile defines: no defines Memory Requirements: - Input buffer: compressed size - Output buffer: uncompressed size |
caf72ff32 Refresh LZMA-lib ... |
332 |
- LZMA Internal Structures: state_size (16 KB for default settings) |
fc9c1727b Add support for L... |
333 334 |
Interface: |
caf72ff32 Refresh LZMA-lib ... |
335 336 337 338 339 340 341 342 343 344 345 |
int LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc); In: dest - output data destLen - output data size src - input data srcLen - input data size propData - LZMA properties (5 bytes) propSize - size of propData buffer (5 bytes) finishMode - It has meaning only if the decoding reaches output limit (*destLen). |
5fe8380db lzma: update to l... |
346 347 |
LZMA_FINISH_ANY - Decode just destLen bytes. LZMA_FINISH_END - Stream must be finished after (*destLen). |
caf72ff32 Refresh LZMA-lib ... |
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
You can use LZMA_FINISH_END, when you know that current output buffer covers last bytes of stream. alloc - Memory allocator. Out: destLen - processed output size srcLen - processed input size Output: SZ_OK status: LZMA_STATUS_FINISHED_WITH_MARK LZMA_STATUS_NOT_FINISHED LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK SZ_ERROR_DATA - Data error SZ_ERROR_MEM - Memory allocation error SZ_ERROR_UNSUPPORTED - Unsupported properties SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). If LZMA decoder sees end_marker before reaching output limit, it returns OK result, and output value of destLen will be less than output buffer size limit. You can use multiple checks to test data integrity after full decompression: 1) Check Result and "status" variable. 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize. 3) Check that output(srcLen) = compressedSize, if you know real compressedSize. You must use correct finish mode in that case. */ Multi-call State Decompressing (zlib-like interface) ---------------------------------------------------- |
fc9c1727b Add support for L... |
379 |
|
caf72ff32 Refresh LZMA-lib ... |
380 381 |
When to use: file->file decompressing Compile files: LzmaDec.h + LzmaDec.c + Types.h |
fc9c1727b Add support for L... |
382 |
|
fc9c1727b Add support for L... |
383 |
Memory Requirements: |
caf72ff32 Refresh LZMA-lib ... |
384 385 386 387 |
- Buffer for input stream: any size (for example, 16 KB) - Buffer for output stream: any size (for example, 16 KB) - LZMA Internal Structures: state_size (16 KB for default settings) - LZMA dictionary (dictionary size is encoded in LZMA properties header) |
fc9c1727b Add support for L... |
388 |
|
caf72ff32 Refresh LZMA-lib ... |
389 390 391 |
1) read LZMA properties (5 bytes) and uncompressed size (8 bytes, little-endian) to header: unsigned char header[LZMA_PROPS_SIZE + 8]; ReadFile(inFile, header, sizeof(header) |
fc9c1727b Add support for L... |
392 |
|
caf72ff32 Refresh LZMA-lib ... |
393 394 395 396 397 398 399 400 401 402 403 404 |
2) Allocate CLzmaDec structures (state + dictionary) using LZMA properties CLzmaDec state; LzmaDec_Constr(&state); res = LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc); if (res != SZ_OK) return res; 3) Init LzmaDec structure before any new LZMA stream. And call LzmaDec_DecodeToBuf in loop LzmaDec_Init(&state); for (;;) |
fc9c1727b Add support for L... |
405 |
{ |
caf72ff32 Refresh LZMA-lib ... |
406 407 |
... int res = LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, |
5fe8380db lzma: update to l... |
408 |
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode); |
caf72ff32 Refresh LZMA-lib ... |
409 |
... |
fc9c1727b Add support for L... |
410 |
} |
fc9c1727b Add support for L... |
411 |
|
caf72ff32 Refresh LZMA-lib ... |
412 413 414 415 416 417 418 419 |
4) Free all allocated structures LzmaDec_Free(&state, &g_Alloc); For full code example, look at C/LzmaUtil/LzmaUtil.c code. How To compress data -------------------- |
fc9c1727b Add support for L... |
420 |
|
caf72ff32 Refresh LZMA-lib ... |
421 422 |
Compile files: LzmaEnc.h + LzmaEnc.c + Types.h + LzFind.c + LzFind.h + LzFindMt.c + LzFindMt.h + LzHash.h |
fc9c1727b Add support for L... |
423 |
|
fc9c1727b Add support for L... |
424 |
Memory Requirements: |
caf72ff32 Refresh LZMA-lib ... |
425 |
- (dictSize * 11.5 + 6 MB) + state_size |
fc9c1727b Add support for L... |
426 |
|
caf72ff32 Refresh LZMA-lib ... |
427 428 429 |
Lzma Encoder can use two memory allocators: 1) alloc - for small arrays. 2) allocBig - for big arrays. |
fc9c1727b Add support for L... |
430 |
|
caf72ff32 Refresh LZMA-lib ... |
431 432 433 434 |
For example, you can use Large RAM Pages (2 MB) in allocBig allocator for better compression speed. Note that Windows has bad implementation for Large RAM Pages. It's OK to use same allocator for alloc and allocBig. |
fc9c1727b Add support for L... |
435 |
|
fc9c1727b Add support for L... |
436 |
|
caf72ff32 Refresh LZMA-lib ... |
437 438 |
Single-call Compression with callbacks -------------------------------------- |
fc9c1727b Add support for L... |
439 |
|
caf72ff32 Refresh LZMA-lib ... |
440 |
Check C/LzmaUtil/LzmaUtil.c as example, |
fc9c1727b Add support for L... |
441 |
|
caf72ff32 Refresh LZMA-lib ... |
442 |
When to use: file->file decompressing |
fc9c1727b Add support for L... |
443 |
|
caf72ff32 Refresh LZMA-lib ... |
444 445 446 447 448 |
1) you must implement callback structures for interfaces: ISeqInStream ISeqOutStream ICompressProgress ISzAlloc |
fc9c1727b Add support for L... |
449 |
|
caf72ff32 Refresh LZMA-lib ... |
450 451 452 |
static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); } static void SzFree(void *p, void *address) { p = p; MyFree(address); } static ISzAlloc g_Alloc = { SzAlloc, SzFree }; |
fc9c1727b Add support for L... |
453 |
|
caf72ff32 Refresh LZMA-lib ... |
454 455 |
CFileSeqInStream inStream; CFileSeqOutStream outStream; |
fc9c1727b Add support for L... |
456 |
|
caf72ff32 Refresh LZMA-lib ... |
457 458 459 460 |
inStream.funcTable.Read = MyRead; inStream.file = inFile; outStream.funcTable.Write = MyWrite; outStream.file = outFile; |
fc9c1727b Add support for L... |
461 |
|
caf72ff32 Refresh LZMA-lib ... |
462 |
2) Create CLzmaEncHandle object; |
fc9c1727b Add support for L... |
463 |
|
caf72ff32 Refresh LZMA-lib ... |
464 |
CLzmaEncHandle enc; |
fc9c1727b Add support for L... |
465 |
|
caf72ff32 Refresh LZMA-lib ... |
466 467 468 |
enc = LzmaEnc_Create(&g_Alloc); if (enc == 0) return SZ_ERROR_MEM; |
fc9c1727b Add support for L... |
469 |
|
caf72ff32 Refresh LZMA-lib ... |
470 |
3) initialize CLzmaEncProps properties; |
fc9c1727b Add support for L... |
471 |
|
caf72ff32 Refresh LZMA-lib ... |
472 |
LzmaEncProps_Init(&props); |
fc9c1727b Add support for L... |
473 |
|
caf72ff32 Refresh LZMA-lib ... |
474 |
Then you can change some properties in that structure. |
fc9c1727b Add support for L... |
475 |
|
caf72ff32 Refresh LZMA-lib ... |
476 |
4) Send LZMA properties to LZMA Encoder |
fc9c1727b Add support for L... |
477 |
|
caf72ff32 Refresh LZMA-lib ... |
478 |
res = LzmaEnc_SetProps(enc, &props); |
fc9c1727b Add support for L... |
479 |
|
caf72ff32 Refresh LZMA-lib ... |
480 |
5) Write encoded properties to header |
fc9c1727b Add support for L... |
481 |
|
caf72ff32 Refresh LZMA-lib ... |
482 483 484 485 |
Byte header[LZMA_PROPS_SIZE + 8]; size_t headerSize = LZMA_PROPS_SIZE; UInt64 fileSize; int i; |
fc9c1727b Add support for L... |
486 |
|
caf72ff32 Refresh LZMA-lib ... |
487 488 489 490 491 |
res = LzmaEnc_WriteProperties(enc, header, &headerSize); fileSize = MyGetFileLength(inFile); for (i = 0; i < 8; i++) header[headerSize++] = (Byte)(fileSize >> (8 * i)); MyWriteFileAndCheck(outFile, header, headerSize) |
fc9c1727b Add support for L... |
492 |
|
caf72ff32 Refresh LZMA-lib ... |
493 494 495 |
6) Call encoding function: res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable, NULL, &g_Alloc, &g_Alloc); |
fc9c1727b Add support for L... |
496 |
|
caf72ff32 Refresh LZMA-lib ... |
497 498 |
7) Destroy LZMA Encoder Object LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc); |
fc9c1727b Add support for L... |
499 |
|
fc9c1727b Add support for L... |
500 |
|
5fe8380db lzma: update to l... |
501 502 |
If callback function return some error code, LzmaEnc_Encode also returns that code or it can return the code like SZ_ERROR_READ, SZ_ERROR_WRITE or SZ_ERROR_PROGRESS. |
fc9c1727b Add support for L... |
503 |
|
caf72ff32 Refresh LZMA-lib ... |
504 505 |
Single-call RAM->RAM Compression -------------------------------- |
fc9c1727b Add support for L... |
506 |
|
caf72ff32 Refresh LZMA-lib ... |
507 508 |
Single-call RAM->RAM Compression is similar to Compression with callbacks, but you provide pointers to buffers instead of pointers to stream callbacks: |
fc9c1727b Add support for L... |
509 |
|
caf72ff32 Refresh LZMA-lib ... |
510 511 512 |
HRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); |
fc9c1727b Add support for L... |
513 |
|
caf72ff32 Refresh LZMA-lib ... |
514 515 516 517 518 519 |
Return code: SZ_OK - OK SZ_ERROR_MEM - Memory allocation error SZ_ERROR_PARAM - Incorrect paramater SZ_ERROR_OUTPUT_EOF - output buffer overflow SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) |
fc9c1727b Add support for L... |
520 |
|
fc9c1727b Add support for L... |
521 |
|
fc9c1727b Add support for L... |
522 |
|
5fe8380db lzma: update to l... |
523 524 |
Defines ------- |
caf72ff32 Refresh LZMA-lib ... |
525 526 527 528 529 |
_LZMA_SIZE_OPT - Enable some optimizations in LZMA Decoder to get smaller executable code. _LZMA_PROB32 - It can increase the speed on some 32-bit CPUs, but memory usage for some structures will be doubled in that case. |
fc9c1727b Add support for L... |
530 |
|
caf72ff32 Refresh LZMA-lib ... |
531 532 533 |
_LZMA_UINT32_IS_ULONG - Define it if int is 16-bit on your compiler and long is 32-bit. _LZMA_NO_SYSTEM_SIZE_T - Define it if you don't want to use size_t type. |
fc9c1727b Add support for L... |
534 |
|
5fe8380db lzma: update to l... |
535 |
_7ZIP_PPMD_SUPPPORT - Define it if you don't want to support PPMD method in AMSI-C .7z decoder. |
fc9c1727b Add support for L... |
536 537 538 539 |
C++ LZMA Encoder/Decoder ~~~~~~~~~~~~~~~~~~~~~~~~ C++ LZMA code use COM-like interfaces. So if you want to use it, you can study basics of COM/OLE. |
caf72ff32 Refresh LZMA-lib ... |
540 |
C++ LZMA code is just wrapper over ANSI-C code. |
fc9c1727b Add support for L... |
541 |
|
fc9c1727b Add support for L... |
542 |
|
caf72ff32 Refresh LZMA-lib ... |
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
C++ Notes ~~~~~~~~~~~~~~~~~~~~~~~~ If you use some C++ code folders in 7-Zip (for example, C++ code for .7z handling), you must check that you correctly work with "new" operator. 7-Zip can be compiled with MSVC 6.0 that doesn't throw "exception" from "new" operator. So 7-Zip uses "CPP\Common\NewHandler.cpp" that redefines "new" operator: operator new(size_t size) { void *p = ::malloc(size); if (p == 0) throw CNewException(); return p; } If you use MSCV that throws exception for "new" operator, you can compile without "NewHandler.cpp". So standard exception will be used. Actually some code of 7-Zip catches any exception in internal code and converts it to HRESULT code. So you don't need to catch CNewException, if you call COM interfaces of 7-Zip. |
fc9c1727b Add support for L... |
560 561 562 563 |
--- http://www.7-zip.org |
caf72ff32 Refresh LZMA-lib ... |
564 |
http://www.7-zip.org/sdk.html |
fc9c1727b Add support for L... |
565 |
http://www.7-zip.org/support.html |