1.概述
lzma是7-Zip压缩项目中7z格式的默认与通用压缩方法,压缩率高,解压速度快,需要的内存小。目录中包括ANSI-C/C++/C#/Java源码,以及用于windows的编译好的文件,以及几个文档:
- lzma.txt - LZMA SDK描述文件
- 7zFormat.txt - 7z格式描述文件
- 7zC.txt - 7z ANSI-C解码描述文件
- methods.txt - .7z文件的压缩方式
- lzma.exe - 编译好的文件,用于windows下文件到文件的解压缩
- 7zr.exe - 编译好的7-Zip,支持7z/lzma/xz等格式
- history.txt - LZMA SDK的历史版本
2.C文件
C文件夹下:
- 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
- Threads.* - The code for multithreading.
Util文件夹下:
- LzmaLib - LZMA库 (.DLL for Windows)
- Lzma - LZMA使用方法 (文件到文件的 LZMA encoder/decoder).
- 7z - 7z ANSI-C 解码器
3.用法
LZMA <e|d> inputFile outputFile [<switches>...]
e: encode file
d: decode file
<Switches>
-a{N}: 压缩模式 0 = fast, 1 = normal
default: 1 (normal)
-d{N}: 字典大小 - [0, 30], default: 23 (8MB)
字典大小最大值为 1 GB = 2^30 bytes.
计算方式为 DictionarySize = 2^N bytes.
对于用LZMA压缩的文件解压,字典大小为 D = 2^N 就需要 D bytes 内存(RAM)
-fb{N}: fast bytes 数 - [5, 273], default: 128
这个数越大,压缩比越大,速度也越慢
-lc{N}: literal context bits 数 - [0, 8], default: 3
对于大文件,通常设置 lc=4.
-lp{N}: literal pos bits 数 - [0, 4], default: 0
当周期为 2^N 时,预留给周期数据.
例如,对于 32-bit (4 bytes),可以设 lp=2.
如果这里有变化,通常要设置 lc0.
-pb{N}: pos bits 数 - [0, 4], default: 2
当周期为 2^N 时,预留给周期数据.
-mf{MF_ID}: Match Finder. Default: bt4.
hc* 组算法压缩比不好, 但当与fast mode(-a0)结合时速度很快.
内存需求取决于字典大小(下表中的参数"d").
MF_ID | Memory | Description |
---|---|---|
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. |