<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh">
	<id>https://arolstar52-zhtest.hf.space/index.php?action=history&amp;feed=atom&amp;title=LZMA</id>
	<title>LZMA - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://arolstar52-zhtest.hf.space/index.php?action=history&amp;feed=atom&amp;title=LZMA"/>
	<link rel="alternate" type="text/html" href="https://arolstar52-zhtest.hf.space/index.php?title=LZMA&amp;action=history"/>
	<updated>2026-07-16T00:26:26Z</updated>
	<subtitle>在这个wiki上该页的修订历史</subtitle>
	<generator>MediaWiki 1.43.9</generator>
	<entry>
		<id>https://arolstar52-zhtest.hf.space/index.php?title=LZMA&amp;diff=168147&amp;oldid=prev</id>
		<title>imported&gt;Willy1018-bot：​BOTR：批量替換所有lang-xx模板為langx模板</title>
		<link rel="alternate" type="text/html" href="https://arolstar52-zhtest.hf.space/index.php?title=LZMA&amp;diff=168147&amp;oldid=prev"/>
		<updated>2025-07-02T14:41:07Z</updated>

		<summary type="html">&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/%E6%9C%BA%E5%99%A8%E4%BA%BA/%E4%BD%9C%E4%B8%9A%E8%AF%B7%E6%B1%82#.E8.AB.8B.E6.B1.82.E6.89.B9.E9.87.8F.E6.9B.BF.E6.8F.9B.E6.89.80.E6.9C.89lang-xx.E6.A8.A1.E6.9D.BF.E7.82.BAlangx.E6.A8.A1.E6.9D.BF&quot; class=&quot;extiw&quot; title=&quot;wikipedia:机器人/作业请求&quot;&gt;BOTR&lt;/a&gt;：批量替換所有lang-xx模板為langx模板&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{noteTA|G1=IT}}&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;LZMA&amp;#039;&amp;#039;&amp;#039;（{{langx|en|Lempel–Ziv–Markov chain algorithm}}）是2001年以来得到发展的一个[[数据压缩]]算法，它用于[[7-Zip]]归档工具中的[[7z]]格式和 [[Unix-like]] 下的 [[xz]] 格式。它使用类似于[[LZ77与LZ78|LZ77]]的{{tsl|en|Dictionary coder|字典编码}}机制，在一般的情況下壓縮率比[[bzip2]]為高，用於壓縮的字典檔案大小可達4GB。&lt;br /&gt;
&lt;br /&gt;
[[C++]]语言写成的LZMA[[开放源码]]压缩库使用了[[区间编码]]支持的[[LZ77与LZ78|LZ77]]改进压缩算法以及特殊的用于二进制的预处理程序。LZMA 对数据流、重复序列大小以及重续序列位置单独进行了压缩。LZMA支持几种[[哈希链|散列链]]变体、[[二叉树]]以及[[基数树]]作为它的字典查找算法基础。&lt;br /&gt;
&lt;br /&gt;
== 特性 ==&lt;br /&gt;
&lt;br /&gt;
=== BCJ / BCJ2二进制文件压缩 ===&lt;br /&gt;
&lt;br /&gt;
BCJ / BCJ2压缩工具所附带的LZMA SDK包括：在[[X86]]、[[ARM]]、[[PowerPC]]、[[IA-64]]以及[[ARM#Thumb|ARM Thumb]]处理器上在压缩之前跳转目标进行归一化处理。对于x86平台来说，这是一个近跳转、近调用以及近条件跳转需要从“向后跳1665字节”这样的机器语言归一化到“跳转到5554”这样的格式，但是短跳转及短条件跳转不需要进行这样的处理。&lt;br /&gt;
&lt;br /&gt;
BCJ与BCJ2之间的区别在于前者只将近跳转及近调用目标地址转换到归一化的形式，而BCJ2只将x86平台下的近跳转、近调用及条件近跳转目标分别进行压缩。&lt;br /&gt;
&lt;br /&gt;
== 实现和可移植性 ==&lt;br /&gt;
&lt;br /&gt;
一些[[Windows作業系統]]专有的特性深深嵌入在原始程序中，使得最初很难生成一个与[[Unix]]等系统兼容的版本。然而，LZMA 由于其[[开放源码]]特性，仍然最终获得了各种平台的实现：&lt;br /&gt;
&lt;br /&gt;
=== 7-Zip/p7zip 参考实现 ===&lt;br /&gt;
&lt;br /&gt;
{{main|7-zip|p7zip}}&lt;br /&gt;
&lt;br /&gt;
在[[GPL|GNU通用公共許可證]]下發佈的 7-zip 參考版本有以下幾個特點：&lt;br /&gt;
&lt;br /&gt;
* 高壓縮比&lt;br /&gt;
* 解壓縮程式碼較小：約5 KB&lt;br /&gt;
* 解壓縮時僅需少量記憶體（取決於字典大小）&lt;br /&gt;
* 解壓縮速度：在一部2GHz的處理器上運行，約可達10-20MB每秒的速度。&lt;br /&gt;
* 支援在[[多核心]]系统上[[多執行緒]]运行（包括[[超執行緒]]）。&lt;br /&gt;
&lt;br /&gt;
这个特点使得这个这个算法的解压过程非常适合于[[嵌入式系统]]应用的场合。p7zip 为 [[7-zip]] 的 POSIX 系统移植。&lt;br /&gt;
&lt;br /&gt;
=== xz 和 LZMA Unix Port ===&lt;br /&gt;
&lt;br /&gt;
{{main|xz}}&lt;br /&gt;
&lt;br /&gt;
LZMA Unix Port 是一个只移植了 7-zip 中 LZMA 压缩代码的版本，内含命令行参数类似于 [[gzip]] 的基于数据流的压缩工具。它不是一个归档工具，而只是一个普通的压缩工具，并且由于它在没有数据头中没有未压缩文件大小的UInt64变量，所以它与7-zip生成的LZMA数据流中不同。[[7-zip]]使用一种更加灵活的归档格式[[7z]]，因此不能由此工具解压。&lt;br /&gt;
&lt;br /&gt;
后来类似的 xz 替代了 LZMA Unix Port，提供了更好的压缩功能，并最终以其优异的性能和压缩比&amp;lt;ref&amp;gt;{{cite web|author1=Lasse Collin|title=A Quick Benchmark: Gzip vs. Bzip2 vs. LZMA|url=http://tukaani.org/lzma/benchmarks.html|accessdate=2015-10-21|ref=gzip_bzip_lzma_bench|date=2005-05-31|archive-date=2020-11-12|archive-url=https://web.archive.org/web/20201112013945/https://tukaani.org/lzma/benchmarks.html}}&amp;lt;/ref&amp;gt;成为了不少开源软件（例如 [[Linux]] 内核源码、[[Debian]] deb&amp;lt;ref name=dpkg_use_xz&amp;gt;{{cite web|author1=Guillem Jover|title=Accepted dpkg 1.17.0 (source amd64 all)|url=http://packages.qa.debian.org/d/dpkg/news/20130727T040302Z.html|website=Debian Package QA|accessdate=2015-10-21|archive-date=2017-07-06|archive-url=https://web.archive.org/web/20170706124615/https://packages.qa.debian.org/d/dpkg/news/20130727T040302Z.html}}&amp;lt;/ref&amp;gt;和 [[Fedora (作業系統)|Fedora]] rpm）的压缩方式之一，甚至是默认压缩方式。xz 命令行程序曾有过一个名为 pxz 的分支，提供多线程压缩功能，后来 xz 在 5.2 时本身就直接提供多线程了。&lt;br /&gt;
&lt;br /&gt;
=== lzip ===&lt;br /&gt;
{{main|{{tsl|en|lzip|}}}}&lt;br /&gt;
&lt;br /&gt;
Lzip 是另一个 [[Unix-like]] 系统下的 LZMA 压缩格式，其主要目的之一就是和 xz 竞争。与 xz 相比，它的最大亮点在于提供更简单的文件格式和因此得来的更方便的数据恢复&amp;lt;ref name=lzip_bench&amp;gt;{{cite web|last1=Diaz|first1=Diaz|title=Lzip Benchmarks|url=http://lzip.nongnu.org/lzip_benchmark.html|publisher=LZIP (nongnu)|access-date=2015-10-21|archive-date=2020-06-07|archive-url=https://web.archive.org/web/20200607220953/http://lzip.nongnu.org/lzip_benchmark.html}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{cite web|title=lziprecover|author1=Antonio Diaz Diaz|url=http://lzip.nongnu.org/lziprecover.html|access-date=2015-10-21|archive-date=2020-06-27|archive-url=https://web.archive.org/web/20200627025910/http://lzip.nongnu.org/lziprecover.html}}&amp;lt;/ref&amp;gt;。Lzip 的格式如此简单以至于其文档中就存在一个解压器实现，于是未来的数据考古学家即使在[[量子计算机]]使得 LZMA 无用多时之后只靠文档也能成功解压文件。&lt;br /&gt;
&lt;br /&gt;
== 应用 ==&lt;br /&gt;
&lt;br /&gt;
使用或者支持LZMA的软件有：&lt;br /&gt;
&lt;br /&gt;
* [[Nullsoft Scriptable Install System]]&lt;br /&gt;
* [[Inno Setup]]&lt;br /&gt;
* [[Linux]] 内核（[[cramfs]]、[[SquashFS]]、[[initrd]] 等）、[[GRUB]]&lt;br /&gt;
* [http://ck.kolivas.org/apps/lrzip/ lrzip] {{Wayback|url=http://ck.kolivas.org/apps/lrzip/ |date=20201130041617 }}（&amp;quot;long range zip&amp;quot;, or &amp;quot;LZMA [[rzip]]&amp;quot;）&lt;br /&gt;
* [http://www.joachim-bauch.de/projects/python/pylzma PyLZMA] {{Wayback|url=http://www.joachim-bauch.de/projects/python/pylzma |date=20100402042916 }}，Igor Pavlov的LZMA SDK的[[Python]]语言接口&lt;br /&gt;
* [http://freearc.narod.ru/ FreeArc] {{Wayback|url=http://freearc.narod.ru/ |date=20201021011924 }}，归档工具及LZMA SDK的[[Haskell]]语言接口&lt;br /&gt;
* 用于[[Pascal語言|Pascal]]语言的[http://www.birtles.org.uk/programming/ LZMA SDK] {{Wayback|url=http://www.birtles.org.uk/programming/ |date=20201128180344 }}&lt;br /&gt;
* [[7-Zip]]&lt;br /&gt;
* [[osu!]](用于记录玩家的游戏回放，[[osu!]]将光标移动信息以LZMA格式压缩为存档。)&lt;br /&gt;
&lt;br /&gt;
== 压缩格式表示 ==&lt;br /&gt;
&lt;br /&gt;
LZMA的压缩输出流是一个比特流，采用自适应二进制行程编码器（adaptive binary range coder）。比特流划分为包（packet），每个包或者表示一个字节的受压缩数据，或者如同LZ77的压缩输出序列那样的长度与距离的对（pair）。每个包得每个部分作为独立的上下文（context），从而对每个比特的概率预测仅相关于前一个包的同类型比特值。&lt;br /&gt;
&lt;br /&gt;
有7类包：&amp;lt;ref&amp;gt;{{Cite web |url=http://7-zip.org/sdk.html |title=the source of LZMA SDK  |access-date=2016-08-04 |archive-date=2014-06-09 |archive-url=https://wayback.archive-it.org/all/20140609200859/http://www.7-zip.org/sdk.html }}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! 包的比特序列&lt;br /&gt;
! 包名&lt;br /&gt;
! 描述&lt;br /&gt;
|-&lt;br /&gt;
| 0 + byteCode&lt;br /&gt;
| LIT&lt;br /&gt;
| 单个字节，采用自适应二进制行程编码器。&lt;br /&gt;
|-&lt;br /&gt;
| 1+0 + len + dist&lt;br /&gt;
| MATCH&lt;br /&gt;
| 一个典型的LZ77序列使用长度与距离。&lt;br /&gt;
|-&lt;br /&gt;
| 1+1+0+0&lt;br /&gt;
| SHORTREP&lt;br /&gt;
| 单个字节的LZ77序列。距离等于上个LZ77包使用的距离。&lt;br /&gt;
|-&lt;br /&gt;
| 1+1+0+1 + len&lt;br /&gt;
| LONGREP[0]&lt;br /&gt;
| 单个LZ77序列。距离等于上个LZ77包使用的距离。&lt;br /&gt;
|-&lt;br /&gt;
| 1+1+1+0 + len&lt;br /&gt;
| LONGREP[1]&lt;br /&gt;
| 单个LZ77序列。距离等于倒数第二个LZ77包使用的距离。&lt;br /&gt;
|-&lt;br /&gt;
| 1+1+1+1+0 + len&lt;br /&gt;
| LONGREP[2]&lt;br /&gt;
| 单个LZ77序列。距离等于倒数第三个LZ77包使用的距离。&lt;br /&gt;
|-&lt;br /&gt;
| 1+1+1+1+1 + len&lt;br /&gt;
| LONGREP[3]&lt;br /&gt;
| 单个LZ77序列。距离等于倒数第四个LZ77包使用的距离。&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
LONGREP[*] 表示LONGREP[0-3]四种包, *REP指称LONGREP 与SHORTREP, *MATCH指称MATCH或*REP.&lt;br /&gt;
&lt;br /&gt;
LONGREP[n]包删除了对距离的直接表示，而是使用包序列最近四个距离。&lt;br /&gt;
&lt;br /&gt;
包的长度部分表示如下：&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! 长度比特序列&lt;br /&gt;
! 描述&lt;br /&gt;
|-&lt;br /&gt;
| 0+ 3 bits&lt;br /&gt;
| 长度用3比特编码，表示 2 到 9.&lt;br /&gt;
|-&lt;br /&gt;
| 1+0+ 3 bits&lt;br /&gt;
| 长度用3比特编码，表示 10到17.&lt;br /&gt;
|-&lt;br /&gt;
| 1+1+ 8 bits&lt;br /&gt;
| 长度用8比特编码，表示 18到273.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
如同LZ77, 长度不一定要小于距离。&lt;br /&gt;
&lt;br /&gt;
距离在逻辑上是32比特，距离0表示最近增加到词典的那个字节。&lt;br /&gt;
&lt;br /&gt;
距离的编码以6比特&amp;quot;distance slot&amp;quot;开始，由此可知后面跟着多少比特来补全。这是可变长编码。&lt;br /&gt;
距离解码后为比特流，从最显著位到最不显著位。distance slots 0−3直接编码了0−3.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! 6-bit distance slot&lt;br /&gt;
! Highest 2 bits&lt;br /&gt;
! Fixed 0.5 probability bits&lt;br /&gt;
! 跟随的比特位数&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 00&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 01&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 10&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| 0&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| 10&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| 10&lt;br /&gt;
| 0&lt;br /&gt;
| 2&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| 2&lt;br /&gt;
|-&lt;br /&gt;
| 8&lt;br /&gt;
| 10&lt;br /&gt;
| 0&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 9&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| 10&lt;br /&gt;
| 0&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 11&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 12&lt;br /&gt;
| 10&lt;br /&gt;
| 0&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 13&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 14–62 (even)&lt;br /&gt;
| 10&lt;br /&gt;
| ((slot / 2) − 5)&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 15–63 (odd)&lt;br /&gt;
| 11&lt;br /&gt;
| (((slot − 1) / 2) − 5)&lt;br /&gt;
| 4&lt;br /&gt;
|}&lt;br /&gt;
== 解压缩算法描述 ==&lt;br /&gt;
依据嵌入到Linux kernel的 [[Xz|XZ]]解码算法源文件&amp;lt;ref&amp;gt;{{cite web&lt;br /&gt;
| url=https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/lib/xz/xz_dec_lzma2.c&lt;br /&gt;
| title=lib/xz/xz_dec_lzma2.c&lt;br /&gt;
| first1=Lasse&lt;br /&gt;
| last1=Collin&lt;br /&gt;
| first2=Igor&lt;br /&gt;
| last2=Pavlov&lt;br /&gt;
| accessdate=2013-06-16&lt;br /&gt;
| archive-date=2019-10-18&lt;br /&gt;
| archive-url=https://web.archive.org/web/20191018032241/https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/xz/xz_dec_lzma2.c&lt;br /&gt;
}}&amp;lt;/ref&amp;gt;。&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
===比特的区间编码===&lt;br /&gt;
&lt;br /&gt;
LZMA data is at the lowest level decoded one bit at a time by the range decoder, at the direction of the LZMA decoder.&lt;br /&gt;
&lt;br /&gt;
Context-based range decoding is invoked by the LZMA algorithm passing it a reference to the &amp;quot;context&amp;quot;, which consists of the unsigned 11-bit variable &amp;#039;&amp;#039;prob&amp;#039;&amp;#039; (typically implemented using a 16-bit data type) representing the predicted probability of the bit being 1, which is read and updated by the range decoder (and should be initialized to 2^10, representing 0.5 probability).&lt;br /&gt;
&lt;br /&gt;
Fixed probability range decoding instead assumes a 0.5 probability, but operates slightly differently from context-based range decoding.&lt;br /&gt;
&lt;br /&gt;
The range decoder state consists of two unsigned 32-bit variables, &amp;#039;&amp;#039;range&amp;#039;&amp;#039; (representing the range size), and &amp;#039;&amp;#039;code&amp;#039;&amp;#039; (representing the encoded point within the range).&lt;br /&gt;
&lt;br /&gt;
Initialization of the range decoder consists of setting &amp;#039;&amp;#039;range&amp;#039;&amp;#039; to 2&amp;lt;sup&amp;gt;32&amp;lt;/sup&amp;gt;&amp;amp;nbsp;−&amp;amp;nbsp;1, and &amp;#039;&amp;#039;code&amp;#039;&amp;#039; to the 32-bit value starting at the second byte in the stream interpreted as big-endian; the first byte in the stream is completely ignored.&lt;br /&gt;
&lt;br /&gt;
Normalization proceeds in this way:&lt;br /&gt;
# Shift both &amp;#039;&amp;#039;range&amp;#039;&amp;#039; and &amp;#039;&amp;#039;code&amp;#039;&amp;#039; left by 8 bits&lt;br /&gt;
# Read a byte from the compressed stream&lt;br /&gt;
# Set the least significant 8 bits of &amp;#039;&amp;#039;code&amp;#039;&amp;#039; to the byte value read&lt;br /&gt;
&lt;br /&gt;
Context-based range decoding of a bit using the &amp;#039;&amp;#039;prob&amp;#039;&amp;#039; probability variable proceeds in this way:&lt;br /&gt;
# If &amp;#039;&amp;#039;range&amp;#039;&amp;#039; is less than 2^24, perform normalization&lt;br /&gt;
# Set &amp;#039;&amp;#039;bound&amp;#039;&amp;#039; to floor(&amp;#039;&amp;#039;range&amp;#039;&amp;#039; / 2^11) * &amp;#039;&amp;#039;prob&amp;#039;&amp;#039;&lt;br /&gt;
# If &amp;#039;&amp;#039;code&amp;#039;&amp;#039; is less than &amp;#039;&amp;#039;bound&amp;#039;&amp;#039;:&lt;br /&gt;
## Set &amp;#039;&amp;#039;range&amp;#039;&amp;#039; to &amp;#039;&amp;#039;bound&amp;#039;&amp;#039;&lt;br /&gt;
## Set &amp;#039;&amp;#039;prob&amp;#039;&amp;#039; to &amp;#039;&amp;#039;prob&amp;#039;&amp;#039; + floor((2^11 - &amp;#039;&amp;#039;prob&amp;#039;&amp;#039;) / 2^5)&lt;br /&gt;
## Return bit 0&lt;br /&gt;
# Otherwise (if &amp;#039;&amp;#039;code&amp;#039;&amp;#039; is greater than or equal to the &amp;#039;&amp;#039;bound&amp;#039;&amp;#039;):&lt;br /&gt;
## Set &amp;#039;&amp;#039;range&amp;#039;&amp;#039; to &amp;#039;&amp;#039;range&amp;#039;&amp;#039; - &amp;#039;&amp;#039;bound&amp;#039;&amp;#039;&lt;br /&gt;
## Set &amp;#039;&amp;#039;code&amp;#039;&amp;#039; to &amp;#039;&amp;#039;code&amp;#039;&amp;#039; - &amp;#039;&amp;#039;bound&amp;#039;&amp;#039;&lt;br /&gt;
## Set &amp;#039;&amp;#039;prob&amp;#039;&amp;#039; to &amp;#039;&amp;#039;prob&amp;#039;&amp;#039; - floor(&amp;#039;&amp;#039;prob&amp;#039;&amp;#039; / 2^5)&lt;br /&gt;
## Return bit 1&lt;br /&gt;
&lt;br /&gt;
Fixed-probability range decoding of a bit proceeds in this way:&lt;br /&gt;
# If &amp;#039;&amp;#039;range&amp;#039;&amp;#039; is less than 2^24, perform normalization&lt;br /&gt;
# Set &amp;#039;&amp;#039;range&amp;#039;&amp;#039; to floor(&amp;#039;&amp;#039;range&amp;#039;&amp;#039; / 2)&lt;br /&gt;
# If &amp;#039;&amp;#039;code&amp;#039;&amp;#039; is less than &amp;#039;&amp;#039;range&amp;#039;&amp;#039;:&lt;br /&gt;
## Return bit 0&lt;br /&gt;
# Otherwise (if &amp;#039;&amp;#039;code&amp;#039;&amp;#039; is greater or equal than &amp;#039;&amp;#039;range&amp;#039;&amp;#039;):&lt;br /&gt;
## Set &amp;#039;&amp;#039;code&amp;#039;&amp;#039; to &amp;#039;&amp;#039;code&amp;#039;&amp;#039; - &amp;#039;&amp;#039;range&amp;#039;&amp;#039;&lt;br /&gt;
## Return bit 1&lt;br /&gt;
&lt;br /&gt;
The Linux kernel implementation of fixed-probability decoding in rc_direct, for performance reasons, doesn&amp;#039;t include a conditional branch, but instead subtracts &amp;#039;&amp;#039;range&amp;#039;&amp;#039; from &amp;#039;&amp;#039;code&amp;#039;&amp;#039; unconditionally, and uses the resulting sign bit to both decide the bit to return, and to generate a mask that is combined with &amp;#039;&amp;#039;code&amp;#039;&amp;#039; and added to &amp;#039;&amp;#039;range&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
Note that:&lt;br /&gt;
# The division by 2^11 when computing &amp;#039;&amp;#039;bound&amp;#039;&amp;#039; and floor operation is done before the multiplication, not after (apparently to avoid requiring fast hardware support for 32-bit multiplication with a 64-bit result)&lt;br /&gt;
# Fixed probability decoding is not strictly equivalent to context-based range decoding with any &amp;#039;&amp;#039;prob&amp;#039;&amp;#039; value, due to the fact that context-based range decoding discards the lower 11 bits of &amp;#039;&amp;#039;range&amp;#039;&amp;#039; before multiplying by &amp;#039;&amp;#039;prob&amp;#039;&amp;#039; as just described, while fixed probability decoding only discards the last bit&lt;br /&gt;
&lt;br /&gt;
===Range coding of integers ===&lt;br /&gt;
&lt;br /&gt;
The range decoder also provides the bit-tree, reverse bit-tree and fixed probability integer decoding facilities, which are used to decode integers, and generalize the single-bit decoding described above.&lt;br /&gt;
To decode unsigned integers less than &amp;#039;&amp;#039;limit&amp;#039;&amp;#039;, an array of (&amp;#039;&amp;#039;limit&amp;#039;&amp;#039;&amp;amp;nbsp;−&amp;amp;nbsp;1) 11-bit probability variables is provided, which are conceptually arranged as the internal nodes of a complete binary tree with &amp;#039;&amp;#039;limit&amp;#039;&amp;#039; leaves.&lt;br /&gt;
&lt;br /&gt;
Non-reverse bit-tree decoding works by keeping a pointer to the tree of variables, which starts at the root. As long as the pointer doesn&amp;#039;t point to a leaf, a bit is decoded using the variable indicated by the pointer, and the pointer is moved to either the left or right children depending on whether the bit is 0 or 1; when the pointer points to a leaf, the number associated with the leaf is returned.&lt;br /&gt;
&lt;br /&gt;
Non-reverse bit-tree decoding thus happens from most significant to least significant bit, stopping when only one value in the valid range is possible (this conceptually allows to have range sizes that are not powers of two, even though LZMA doesn&amp;#039;t make use of this).&lt;br /&gt;
&lt;br /&gt;
Reverse bit-tree decoding instead decodes from least significant bit to most significant bits, and thus only supports ranges that are powers of two, and always decodes the same number of bits. It is equivalent to performing non-reverse bittree decoding with a power of two &amp;#039;&amp;#039;limit&amp;#039;&amp;#039;, and reversing the last log2(&amp;#039;&amp;#039;limit&amp;#039;&amp;#039;) bits of the result.&lt;br /&gt;
&lt;br /&gt;
Note that in the rc_bittree function in the Linux kernel, integers are actually returned in the [&amp;#039;&amp;#039;limit&amp;#039;&amp;#039;, 2 * &amp;#039;&amp;#039;limit&amp;#039;&amp;#039;) range (with &amp;#039;&amp;#039;limit&amp;#039;&amp;#039; added to the conceptual value), and the variable at index 0 in the array is unused, while the one at index 1 is the root, and the left and right children indices are computed as 2&amp;#039;&amp;#039;i&amp;#039;&amp;#039; and 2&amp;#039;&amp;#039;i&amp;#039;&amp;#039; + 1. The rc_bittree_reverse function instead adds integers in the [0, &amp;#039;&amp;#039;limit&amp;#039;&amp;#039;) range to a caller-provided variable, where &amp;#039;&amp;#039;limit&amp;#039;&amp;#039; is implicitly represented by its logarithm, and has its own independent implementation for efficiency reasons.&lt;br /&gt;
&lt;br /&gt;
Fixed probability integer decoding simply performs fixed probability bit decoding repeatedly, reading bits from the most to the least significant.&lt;br /&gt;
&lt;br /&gt;
===LZMA configuration===&lt;br /&gt;
&lt;br /&gt;
The LZMA decoder is configured by an &amp;#039;&amp;#039;lclppb&amp;#039;&amp;#039; &amp;quot;properties&amp;quot; byte and a dictionary size.&lt;br /&gt;
&lt;br /&gt;
The value of the &amp;#039;&amp;#039;lclppb&amp;#039;&amp;#039; byte is &amp;#039;&amp;#039;lc&amp;#039;&amp;#039; + &amp;#039;&amp;#039;lp&amp;#039;&amp;#039; * 9 + &amp;#039;&amp;#039;pb&amp;#039;&amp;#039; * 9 * 5, where:&lt;br /&gt;
*&amp;#039;&amp;#039;lc&amp;#039;&amp;#039; is the number of high bits of the previous byte to use as a context for literal encoding (the default value used by the LZMA SDK is 3)&lt;br /&gt;
*&amp;#039;&amp;#039;lp&amp;#039;&amp;#039; is the number of low bits of the dictionary position to include in &amp;#039;&amp;#039;literal_pos_state&amp;#039;&amp;#039; (the default value used by the LZMA SDK is 0)&lt;br /&gt;
*&amp;#039;&amp;#039;pb&amp;#039;&amp;#039; is the number of low bits of the dictionary position to include in &amp;#039;&amp;#039;pos_state&amp;#039;&amp;#039; (the default value used by the LZMA SDK is 2)&lt;br /&gt;
&lt;br /&gt;
In non-LZMA2 streams, &amp;#039;&amp;#039;lc&amp;#039;&amp;#039; must not be greater than 8, and &amp;#039;&amp;#039;lp&amp;#039;&amp;#039; and &amp;#039;&amp;#039;pb&amp;#039;&amp;#039; must not be greater than 4.&lt;br /&gt;
In LZMA2 streams, (&amp;#039;&amp;#039;lc&amp;#039;&amp;#039; + &amp;#039;&amp;#039;lp&amp;#039;&amp;#039;) and &amp;#039;&amp;#039;pb&amp;#039;&amp;#039; must not be greater than 4.&lt;br /&gt;
&lt;br /&gt;
In the 7-zip LZMA file format, configuration is performed by a header containing the &amp;quot;properties&amp;quot; byte followed by the 32-bit little-endian dictionary size in bytes. In LZMA2, the properties byte can optionally be changed at the start of LZMA2 LZMA packets, while the dictionary size is specified in the LZMA2 header as later described.&lt;br /&gt;
&lt;br /&gt;
===LZMA coding contexts===&lt;br /&gt;
&lt;br /&gt;
The LZMA packet format has already been described, and this section specifies how LZMA statistically models the LZ-encoded streams, or in other words which probability variables are passed to the range decoder to decode each bit.&lt;br /&gt;
&lt;br /&gt;
Those probability variables are implemented as multi-dimensional arrays; before introducing them, a few values that are used as indices in these multidimensional arrays are defined.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;state&amp;#039;&amp;#039; value is conceptually based on which of the patterns in the following table match the latest 2-4 packet types seen, and is implemented as a state machine state updated according to the transition table listed in the table every time a packet is output.&lt;br /&gt;
&lt;br /&gt;
The initial state is 0, and thus packets before the beginning are assumed to be LIT packets.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! state&lt;br /&gt;
! colspan=&amp;quot;4&amp;quot; | previous packets&lt;br /&gt;
! colspan=&amp;quot;4&amp;quot; | next state when next packet is&lt;br /&gt;
|-&lt;br /&gt;
!&lt;br /&gt;
! 4th previous&lt;br /&gt;
! 3rd previous&lt;br /&gt;
! 2nd previous&lt;br /&gt;
! previous&lt;br /&gt;
! LIT&lt;br /&gt;
! MATCH&lt;br /&gt;
! LONGREP[*]&lt;br /&gt;
! SHORTREP&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
|&lt;br /&gt;
| LIT&lt;br /&gt;
| LIT&lt;br /&gt;
| LIT&lt;br /&gt;
| 0&lt;br /&gt;
| 7&lt;br /&gt;
| 8&lt;br /&gt;
| 9&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|&lt;br /&gt;
| MATCH&lt;br /&gt;
| LIT&lt;br /&gt;
| LIT&lt;br /&gt;
| 0&lt;br /&gt;
| 7&lt;br /&gt;
| 8&lt;br /&gt;
| 9&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | 2&lt;br /&gt;
|&lt;br /&gt;
| LONGREP[*]&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | LIT&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | LIT&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | 0&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | 7&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | 8&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | 9&lt;br /&gt;
|-&lt;br /&gt;
| *MATCH&lt;br /&gt;
| SHORTREP&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| LIT&lt;br /&gt;
| SHORTREP&lt;br /&gt;
| LIT&lt;br /&gt;
| LIT&lt;br /&gt;
| 0&lt;br /&gt;
| 7&lt;br /&gt;
| 8&lt;br /&gt;
| 9&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
| MATCH&lt;br /&gt;
| LIT&lt;br /&gt;
| 1&lt;br /&gt;
| 7&lt;br /&gt;
| 8&lt;br /&gt;
| 9&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | 5&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; |&lt;br /&gt;
|&lt;br /&gt;
| LONGREP[*]&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | LIT&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | 2&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | 7&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | 8&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | 9&lt;br /&gt;
|-&lt;br /&gt;
| *MATCH&lt;br /&gt;
| SHORTREP&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
|&lt;br /&gt;
| LIT&lt;br /&gt;
| SHORTREP&lt;br /&gt;
| LIT&lt;br /&gt;
| 3&lt;br /&gt;
| 7&lt;br /&gt;
| 8&lt;br /&gt;
| 9&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
| LIT&lt;br /&gt;
| MATCH&lt;br /&gt;
| 4&lt;br /&gt;
| 10&lt;br /&gt;
| 11&lt;br /&gt;
| 11&lt;br /&gt;
|-&lt;br /&gt;
| 8&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
| LIT&lt;br /&gt;
| LONGREP[*]&lt;br /&gt;
| 5&lt;br /&gt;
| 10&lt;br /&gt;
| 11&lt;br /&gt;
| 11&lt;br /&gt;
|-&lt;br /&gt;
| 9&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
| LIT&lt;br /&gt;
| SHORTREP&lt;br /&gt;
| 6&lt;br /&gt;
| 10&lt;br /&gt;
| 11&lt;br /&gt;
| 11&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
| *MATCH&lt;br /&gt;
| MATCH&lt;br /&gt;
| 4&lt;br /&gt;
| 10&lt;br /&gt;
| 11&lt;br /&gt;
| 11&lt;br /&gt;
|-&lt;br /&gt;
| 11&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
| *MATCH&lt;br /&gt;
| *REP&lt;br /&gt;
| 5&lt;br /&gt;
| 10&lt;br /&gt;
| 11&lt;br /&gt;
| 11&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;pos_state&amp;#039;&amp;#039; and &amp;#039;&amp;#039;literal_pos_state&amp;#039;&amp;#039; values consist of respectively the &amp;#039;&amp;#039;pb&amp;#039;&amp;#039; and &amp;#039;&amp;#039;lp&amp;#039;&amp;#039; (up to 4, from the LZMA header or LZMA2 properties packet) least significant bits of the dictionary position (the number of bytes coded since the last dictionary reset modulo the dictionary size). Note that the dictionary size is normally the multiple of a large power of 2, so these values are equivalently described as the least significant bits of the number of uncompressed bytes seen since the last dictionary reset.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;prev_byte_lc_msbs&amp;#039;&amp;#039; value is set to the &amp;#039;&amp;#039;lc&amp;#039;&amp;#039; (up to 4, from the LZMA header or LZMA2 properties packet) most significant bits of the previous uncompressed byte.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;is_REP&amp;#039;&amp;#039; value denotes whether a packet that includes a length is a LONGREP rather than a MATCH.&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;match_byte&amp;#039;&amp;#039; value is the byte that would have been decoded if a SHORTREP packet had been used (in other words, the byte found at the dictionary at the last used distance); it is only used just after a *MATCH packet.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;literal_bit_mode&amp;#039;&amp;#039; is an array of 8 values in the 0-2 range, one for each bit position in a byte, which are 1 or 2 if the previous packet was a *MATCH and it is either the most significant bit position or all the more significant bits in the literal to encode/decode are equal to the bits in the corresponding positions in &amp;#039;&amp;#039;match_byte&amp;#039;&amp;#039;, while otherwise it is 0; the choice between the 1 or 2 values depends on the value of the bit at the same position in &amp;#039;&amp;#039;match_byte&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The literal/Literal set of variables can be seen as a &amp;quot;pseudo-bit-tree&amp;quot; similar to a bit-tree but with 3 variables instead of 1 in every node, chosen depending on the &amp;#039;&amp;#039;literal_bit_mode&amp;#039;&amp;#039; value at the bit position of the next bit to decode after the bit-tree context denoted by the node.&lt;br /&gt;
&lt;br /&gt;
The claim, found in some sources, that literals after a *MATCH are coded as the XOR of the byte value with &amp;#039;&amp;#039;match_byte&amp;#039;&amp;#039; is incorrect; they are instead coded simply as their byte value, but using the pseudo-bit-tree just described and the additional context listed in the table below.&lt;br /&gt;
&lt;br /&gt;
The probability variable groups used in LZMA are those:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! XZ name&lt;br /&gt;
! LZMA SDK name&lt;br /&gt;
! parameterized by&lt;br /&gt;
! used when&lt;br /&gt;
! coding mode&lt;br /&gt;
! if bit 0 then&lt;br /&gt;
! if bit 1 then&lt;br /&gt;
|-&lt;br /&gt;
| is_match&lt;br /&gt;
| IsMatch&lt;br /&gt;
| &amp;#039;&amp;#039;state&amp;#039;&amp;#039;, &amp;#039;&amp;#039;pos_state&amp;#039;&amp;#039;&lt;br /&gt;
| packet start&lt;br /&gt;
| bit&lt;br /&gt;
| LIT&lt;br /&gt;
| *MATCH&lt;br /&gt;
|-&lt;br /&gt;
| is_rep&lt;br /&gt;
| IsRep&lt;br /&gt;
| &amp;#039;&amp;#039;state&amp;#039;&amp;#039;&lt;br /&gt;
| after bit sequence 1&lt;br /&gt;
| bit&lt;br /&gt;
| MATCH&lt;br /&gt;
| *REP&lt;br /&gt;
|-&lt;br /&gt;
| is_rep0&lt;br /&gt;
| IsRepG0&lt;br /&gt;
| &amp;#039;&amp;#039;state&amp;#039;&amp;#039;&lt;br /&gt;
| after bit sequence 11&lt;br /&gt;
| bit&lt;br /&gt;
| SHORTREP/&lt;br /&gt;
LONGREP[0]&lt;br /&gt;
| LONGREP[1-3]&lt;br /&gt;
|-&lt;br /&gt;
| is_rep0_long&lt;br /&gt;
| IsRep0Long&lt;br /&gt;
| &amp;#039;&amp;#039;state&amp;#039;&amp;#039;, &amp;#039;&amp;#039;pos_state&amp;#039;&amp;#039;&lt;br /&gt;
| after bit sequence 110&lt;br /&gt;
| bit&lt;br /&gt;
| SHORTREP&lt;br /&gt;
| LONGREP[0]&lt;br /&gt;
|-&lt;br /&gt;
| is_rep1&lt;br /&gt;
| IsRepG1&lt;br /&gt;
| &amp;#039;&amp;#039;state&amp;#039;&amp;#039;&lt;br /&gt;
| after bit sequence 111&lt;br /&gt;
| bit&lt;br /&gt;
| LONGREP[1]&lt;br /&gt;
| LONGREP[2/3]&lt;br /&gt;
|-&lt;br /&gt;
| is_rep2&lt;br /&gt;
| IsRepG2&lt;br /&gt;
| &amp;#039;&amp;#039;state&amp;#039;&amp;#039;&lt;br /&gt;
| after bit sequence 1111&lt;br /&gt;
| bit&lt;br /&gt;
| LONGREP[2]&lt;br /&gt;
| LONGREP[3]&lt;br /&gt;
|-&lt;br /&gt;
| literal&lt;br /&gt;
| Literal&lt;br /&gt;
| &amp;#039;&amp;#039;prev_byte_lc_msbs&amp;#039;&amp;#039;, &amp;#039;&amp;#039;literal_pos_state&amp;#039;&amp;#039;, &amp;#039;&amp;#039;literal_bit_mode&amp;#039;&amp;#039;[bit position], bit-tree context&lt;br /&gt;
| after bit sequence 0&lt;br /&gt;
| 256 values pseudo-bit-tree&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; | literal byte value&lt;br /&gt;
|-&lt;br /&gt;
| dist_slot&lt;br /&gt;
| PosSlot&lt;br /&gt;
| min(&amp;#039;&amp;#039;match_length&amp;#039;&amp;#039;, 5), bit-tree context&lt;br /&gt;
| distance: start&lt;br /&gt;
| 64 values bit-tree&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; | distance slot&lt;br /&gt;
|-&lt;br /&gt;
| dist_special&lt;br /&gt;
| SpecPos&lt;br /&gt;
| &amp;#039;&amp;#039;distance_slot&amp;#039;&amp;#039;, reverse bit-tree context&lt;br /&gt;
| distance: 4-13 distance slots&lt;br /&gt;
| ((&amp;#039;&amp;#039;distance_slot&amp;#039;&amp;#039; &amp;gt;&amp;gt; 1) − 1)-bit reverse bit-tree&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; | low bits of distance&lt;br /&gt;
|-&lt;br /&gt;
| dist_align&lt;br /&gt;
| Align&lt;br /&gt;
| reverse bit-tree context&lt;br /&gt;
| distance: 14+ distance slots, after fixed probability bits&lt;br /&gt;
| 4-bit reverse bit-tree&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; | low bits of distance&lt;br /&gt;
|-&lt;br /&gt;
| len_dec.choice&lt;br /&gt;
| LenChoice&lt;br /&gt;
| &amp;#039;&amp;#039;is_REP&amp;#039;&amp;#039;&lt;br /&gt;
| match length: start&lt;br /&gt;
| bit&lt;br /&gt;
| 2-9 length&lt;br /&gt;
| 10+ length&lt;br /&gt;
|-&lt;br /&gt;
| len_dec.choice2&lt;br /&gt;
| LenChoice2&lt;br /&gt;
| &amp;#039;&amp;#039;is_REP&amp;#039;&amp;#039;&lt;br /&gt;
| match length: after bit sequence 1&lt;br /&gt;
| bit&lt;br /&gt;
| 10-17 length&lt;br /&gt;
| 18+ length&lt;br /&gt;
|-&lt;br /&gt;
| len_dec.low&lt;br /&gt;
| LenLow&lt;br /&gt;
| &amp;#039;&amp;#039;is_REP&amp;#039;&amp;#039;, &amp;#039;&amp;#039;pos_state&amp;#039;&amp;#039;, bit-tree context&lt;br /&gt;
| match length: after bit sequence 0&lt;br /&gt;
| 8 values bit-tree&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; | low bits of length&lt;br /&gt;
|-&lt;br /&gt;
| len_dec.mid&lt;br /&gt;
| LenMid&lt;br /&gt;
| &amp;#039;&amp;#039;is_REP&amp;#039;&amp;#039;, &amp;#039;&amp;#039;pos_state&amp;#039;&amp;#039;, bit-tree context&lt;br /&gt;
| match length: after bit sequence 10&lt;br /&gt;
| 8 values bit-tree&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; | middle bits of length&lt;br /&gt;
|-&lt;br /&gt;
| len_dec.high&lt;br /&gt;
| LenHigh&lt;br /&gt;
| &amp;#039;&amp;#039;is_REP&amp;#039;&amp;#039;, bit-tree context&lt;br /&gt;
| match length: after bit sequence 11&lt;br /&gt;
| 256 values bit-tree&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; | high bits of length&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===LZMA2 format===&lt;br /&gt;
&lt;br /&gt;
The LZMA2 container supports multiple runs of compressed LZMA data and uncompressed data. Each LZMA compressed run can have a different LZMA configuration and dictionary. This improves the compression of partially or completely incompressible files and allows multithreaded compression and multithreaded decompression by breaking the file into runs that can be compressed or decompressed independently in parallel.&lt;br /&gt;
&lt;br /&gt;
The LZMA2 header consists of a byte indicating the dictionary size:&lt;br /&gt;
* 40 indicates a 4 GB − 1 dictionary size&lt;br /&gt;
* Even values less than 40 indicate a 2&amp;lt;sup&amp;gt;&amp;#039;&amp;#039;v&amp;#039;&amp;#039;/2 + 12&amp;lt;/sup&amp;gt; bytes dictionary size&lt;br /&gt;
* Odd values less than 40 indicate a 3×2&amp;lt;sup&amp;gt;(&amp;#039;&amp;#039;v&amp;#039;&amp;#039; − 1)/2 + 11&amp;lt;/sup&amp;gt; bytes dictionary size&lt;br /&gt;
* Values higher than 40 are invalid&lt;br /&gt;
&lt;br /&gt;
LZMA2 data consists of packets starting with a control byte, with the following values:&lt;br /&gt;
* 0 denotes the end of the file&lt;br /&gt;
* 1 denotes a dictionary reset followed by an uncompressed chunk&lt;br /&gt;
* 2 denotes an uncompressed chunk without a dictionary reset&lt;br /&gt;
* 3-0x7f are invalid values&lt;br /&gt;
* 0x80-0xff denotes an LZMA chunk, where the lowest 5 bits are used as bit 16-20 of the uncompressed size minus one, and bit 5-6 indicates what should be reset&lt;br /&gt;
&lt;br /&gt;
Bits 5-6 for LZMA chunks can be:&lt;br /&gt;
* 0: nothing reset&lt;br /&gt;
* 1: state reset&lt;br /&gt;
* 2: state reset, properties reset using properties byte&lt;br /&gt;
* 3: state reset,  properties reset using properties byte, dictionary reset&lt;br /&gt;
&lt;br /&gt;
LZMA state resets cause a reset of all LZMA state except the dictionary, and specifically:&lt;br /&gt;
* The range coder&lt;br /&gt;
* The &amp;#039;&amp;#039;state&amp;#039;&amp;#039; value&lt;br /&gt;
* The last distances for repeated matches&lt;br /&gt;
* All LZMA probabilities&lt;br /&gt;
&lt;br /&gt;
Uncompressed chunks consist of:&lt;br /&gt;
* A 16-bit big-endian value encoding the data size minus one&lt;br /&gt;
* The data to be copied verbatim into the dictionary and the output&lt;br /&gt;
&lt;br /&gt;
LZMA chunks consist of:&lt;br /&gt;
* A 16-bit big-endian value encoding the low 16-bits of the uncompressed size minus one&lt;br /&gt;
* A 16-bit big-endian value encoding the compressed size minus one&lt;br /&gt;
* A properties/lclppb byte if bit 6 in the control byte is set&lt;br /&gt;
* The LZMA compressed data, starting with the 5 bytes (of which the first is ignored) used to initialize the range coder (which are included in the compressed size)&lt;br /&gt;
 --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 參考資料 ==&lt;br /&gt;
{{reflist}}&lt;br /&gt;
&lt;br /&gt;
== 外部链接 ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.7-zip.org/ 7-Zip Official Web-Site] {{Wayback|url=http://www.7-zip.org/ |date=20060512045746 }}&lt;br /&gt;
* [http://www.7-zip.org/sdk.html LZMA SDK] {{Wayback|url=http://www.7-zip.org/sdk.html |date=20210202185328 }}&lt;br /&gt;
* [http://sourceforge.net/projects/p7zip/ p7zip Unix port of command-line utilities] {{Wayback|url=http://sourceforge.net/projects/p7zip/ |date=20210202185255 }}&lt;br /&gt;
* [http://www.joachim-bauch.de/projects/python/pylzma PyLZMA Python Wrapper] {{Wayback|url=http://www.joachim-bauch.de/projects/python/pylzma |date=20100402042916 }}&lt;br /&gt;
* [https://web.archive.org/web/20080516065536/http://nsis.sourceforge.net/ Nullsoft Installer uses LZMA]&lt;br /&gt;
* [http://www.jrsoftware.org/isinfo.php Inno Setup supports LZMA] {{Wayback|url=http://www.jrsoftware.org/isinfo.php |date=20210126030059 }}&lt;br /&gt;
* [https://web.archive.org/web/20060903100509/http://www.fromconcentratesoftware.com/Compress/ Compress home page]&lt;br /&gt;
* [http://babel.ls.fi.upm.es/~aacosta/twiki/bin/view/Projects/CramfsPatches LZMA support for cramfs filesystem]{{Dead link|date=2019年5月 |bot=InternetArchiveBot |fix-attempted=yes }}（dead）&lt;br /&gt;
* [http://tukaani.org/lzma/ LZMA utils] {{Wayback|url=http://tukaani.org/lzma/ |date=20201027013625 }}&lt;br /&gt;
* [http://freearc.narod.ru/ FreeArc archiver and Haskell interface to the LZMA library] {{Wayback|url=http://freearc.narod.ru/ |date=20201021011924 }}&lt;br /&gt;
* [http://search.cpan.org/search?query=lzma at least one perl interface to LZMA library has been published] {{Wayback|url=http://search.cpan.org/search?query=lzma |date=20191018032240 }}&lt;br /&gt;
* [http://www.birtles.org.uk/programming/ Pascal port of the LZMA SDK] {{Wayback|url=http://www.birtles.org.uk/programming/ |date=20201128180344 }}&lt;br /&gt;
&lt;br /&gt;
{{压缩方法}}&lt;br /&gt;
{{Archive formats}}&lt;br /&gt;
&lt;br /&gt;
[[Category:无损压缩算法]]&lt;br /&gt;
[[Category:以色列发明]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Willy1018-bot</name></author>
	</entry>
</feed>