Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

356 lines
12 KiB

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