iczelia/bzip3

GitHub: iczelia/bzip3

bzip3 是 BZip2 的精神继承者,通过先进熵编码与变换算法在压缩率与性能间取得更好平衡。

Stars: 1182 | Forks: 57

# BZip3 [![Build](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/2d5e7b61ec110201.svg)](https://github.com/iczelia/bzip3/actions/workflows/build.yml) 一个更好、更快、更强的 BZip2 精神继承者。由于采用零阶上下文混合熵编码器、利用后缀数组的快速 Burrows-Wheeler 变换代码,以及基于 LZ77 风格字符串匹配和 PPM 风格上下文建模的 RLE 与 Lempel Ziv+Prediction 传递,BZip3 具备更高的压缩比和更优的性能。 与它的祖先一样,**BZip3 在压缩文本或代码方面表现出色**。 ## 安装 ``` # 如果使用 git clone(非源代码包必需),首先... $ ./bootstrap.sh # 全部... $ ./configure $ make $ sudo make install ``` 另外,你也可以通过系统的包管理器安装 bzip3: [![Packaging status](https://repology.org/badge/vertical-allrepos/bzip3.svg?columns=3)](https://repology.org/project/bzip3/versions) 在 macOS 上,你可以使用 [Homebrew](https://brew.sh) 轻松安装: ``` $ brew install bzip3 ``` ## Perl 源码基准测试 首先,我下载了所有发布的 Perl5 版本并进行解压。 ``` % wget -r -l1 -nH --cut-dirs=2 --no-parent -A.tar.gz --no-directories https://www.cpan.org/src/5.0/ % for g in *.gz; do gunzip $g; done % ls -la | wc -l 262 ``` 然后,将所有生成的 `.tar` 文件合并为一个 `.tar` 文件,并尝试使用多种压缩器进行压缩: ``` xz -T16 -9 -k all.tar 10829.91s user 26.91s system 1488% cpu 14658M memory 12:09.24 total bzip2 -9 -k all.tar 981.78s user 9.77s system 95% cpu 8M memory 17:16.64 total bzip3 -e -b 256 -j 12 all.tar 2713.81s user 16.28s system 634% cpu 18301M memory 7:10.10 total bzip3 -e -b 511 -j 4 all.tar 17.65s user 12.19s system 170% cpu 12178M memory 7:08.65 total zstd -T12 -16 all.tar 4162.94s user 16.40s system 1056% cpu 687M memory 6:35.62 total ``` 结果如下: | 方法 | 压缩后大小(字节) | | ---------------- | -----------------------:| | LZMA (xz) | 2'056'645'240 | | bzip2 | 3'441'163'911 | | bzip3 -b 256 | 1'001'957'587 | | bzip3 -b 511 | 546'456'978 | | Zstandard | 3'076'143'660 | 最后,墙钟时间解压时间(WD Blue HDD): | 方法 | 解压时间 | | ---------------- | ------------------:| | LZMA (xz) | 4分40秒 | | bzip2 | 9分22秒 | | bzip3 (并行) | 4分06秒 | | Zstandard | 3分51秒 | 接着,我使用 `lrzip` 对原始 `.tar` 文件执行长距离去重: ``` % time lrzip -n -o all_none.tar.lrz all.tar 546.17s user 160.87s system 102% cpu 10970M memory 11:28.00 total % time lrzip --lzma -o all_lzma.tar.lrz all.tar 702.16s user 161.87s system 122% cpu 10792M memory 11:44.83 total % time lrzip -b -o all_bzip2.tar.lrz all.tar 563.93s user 147.38s system 112% cpu 10970M memory 10:34.10 total ``` 最后,将得到的 `none.tar.lrz` 文件用 bzip3 压缩: ``` % time bzip3 -e -b 256 -j 2 all_none.tar.lrz 32.05s user 0.76s system 146% cpu 2751M memory 22.411 total ``` 结果如下: | 方法 | 压缩后大小(字节) | | ---------------- | -----------------------:| | lrzip + bzip3 | 60'672'608 | | lrzip + lzma | 64'774'202 | | lrzip + bzip2 | 75'685'065 | 如需查看针对 Turbo-Range-Coder 和 BSC 的更多基准测试,请查阅 [powturbo's benchmark](https://github.com/powturbo/Turbo-Range-Coder)。 ## 免责声明 **我不对因使用本程序/库而造成的任何数据损失承担责任,无论其原因如何。** 对每个文件的压缩都隐含假设压缩后的文件可以被解压以还原原始内容。在设计、编码和测试方面已付出巨大努力,以确保该程序正确运行。 然而,由于算法的复杂性,尤其是代码中出现的各种在极低但非零概率下发生的特殊情况,无法完全排除程序中仍存在 bug 的可能性。 除非你准备好接受数据无法恢复的可能性(无论概率多小),否则**不要使用本程序压缩任何数据**。 这并不是说该程序本身不可靠。事实上,我非常希望情况恰恰相反。Bzip3/libbz3 已被精心构建并广泛测试。 **Bzip3 的性能在很大程度上依赖于编译器。x64 Linux clang13 构建通常每个线程的压缩速度可达 17MiB/s,解压速度可达 23MiB/s。Windows 和 32 位构建可能会显著更慢。** Bzip3 已在以下架构上测试通过: - x86 - x86_64 - armv6 - armv7 - aarch64 - ppc64le - mips - mips64 - sparc - s390x ## 语料库基准测试 ![benchmark visualisation](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/99f1acb5bf110203.png) 更多结果请查看 etc/BENCHMARKS.md。 ## 许可证 各组件及其许可证如下: - (运行时) 整体代码库:Copyright 2022-2023, Kamila Szewczyk (k@iczelia.net);LGPL (LICENSE) - (运行时) Burrows-Wheeler 变换 (libsais) 和 LZP 代码:2021-2022, Ilya Grebnov (ilya.grebnov@gmail.com);Apache 2.0 (3rdparty/libsais-LICENSE) - (编译时) `build-aux`:Copyright 2011, Daniel Richard G (skunk@iSKUNK.ORG),2019, Marc Stevens (marc.stevens@cwi.nl),2008, Steven G. Johnson (stevenj@alum.mit.edu);GPL-3+ with AutoConf exception - (编译时) `build-aux/ax_check_compile_flag.m4`:Copyright 2008, Guido U. Draheim (guidod@gmx.de),2011, Maarten Bosmans (mkbosmans@gmail.com);FSFAP - (编译时) `build-aux/git-version-gen`:Copyright 2007-2012, Free Software Foundation, Inc;GPLv3 - (运行时) `bz3grep`:Copyright 2003, Thomas Klausner;BSD-2-clause `bzip3` 整体仅根据 LGPLv3 授权。它**不**在 LGPLv3 和 Apache 2.0 下双重授权。 ## 感谢 - 感谢 Ilya Grebnov 提供的 `libsais` 库(用于 BZip3 中的 BWT 构造)以及 LZP 编码器,我将其作为参考实现以改进自身。 - 感谢 Caleb Maclennan 将 autotools 配置为适合打包的构建系统。 - 感谢 Ilya Muravyov 提供的公共领域 BWT 后编码器,其衍生版本被用于本项目。
标签:Burrows-Wheeler变换, BZip2, bzip3, BZip3, LZ77, PPM, RLE, 上下文建模, 代码压缩, 压缩比, 压缩算法, 后缀数组, 客户端加密, 开源压缩, 快速压缩, 数据压缩, 数据压缩工具, 文本压缩, 熵编码, 精神继承, 软件开发, 高性能压缩