kanzi-go

flangletApache-2.0活跃维护

用 Go 实现的无损数据压缩库,支持 LZ77、BWT、Huffman 等多种算法组合,适合需要高压缩比和并发处理的场景。

Fast lossless data compression in Go

v2.6.0发布于 2026-09-20 16:00 UTC621star +1 / 7 天17fork同步于 2026-11-10 23:55 UTC

怎么上手

由 README 提炼,执行前请确认
go install github.com/flanglet/kanzi-go/v2/[email protected]
硬件要求按 README 说明

README 未说明具体硬件要求;仅提及通过内置多线程利用多核 CPU,基准测试在 AMD Ryzen 9950X 与 Apple M3 上运行。

支持 Apple Silicon
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

Go 编写的模块化无损压缩器,用多线程和 BWT/CM 算法突破 LZ 压缩比上限

用 Go 实现的无损数据压缩库,支持 LZ77、BWT、Huffman 等多种算法组合,适合需要高压缩比和并发处理的场景。

核心能力

  • 运行时自由组合熵编码与数据变换
  • 多线程并行压缩多个数据块
  • 内置多媒体、DNA、UTF 文本等专用变换
  • 输出可寻址比特流,支持按块独立解压
  • 接口驱动设计且无外部依赖,便于扩展

容易踩的坑

不兼容 zstd、gzip 等标准压缩格式,产物只能用 Kanzi 解压;它是压缩器而非归档器,不提供跨文件去重或数据恢复;比特流兼容性只在正式 release 之间保证,自行从最新 tag 构建可能因比特流变更而不兼容。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v2.6.0
  1. v2.6.0最新正式版2026-09-20 · 2026-09-20 16:00 UTC
    • Bug fixes
    • Hardening against invalid and tampered bitstreams
    • A few scattered performance improvements
    • Significant compression improvement on (uncompressed) multimedia files
    • Reconcile the bitstream with the C++ and Java versions (fixed a drift due to bugs in TPAQ and hash64 in the previous release)
    • Entropy is now automatically bypassed if it expands the block size
  2. v2.5.12026-04-23 · 2026-04-23 16:30 UTC
    查看更新说明
    • Bug fixes
  3. v2.5.02026-03-01 · 2026-03-01 02:51 UTC
    查看更新说明
    • New 'info' option to see the characteristics of a compressed bitstream
    • Optimized LZ codec improves compression ratio
    • Hardened code: more bound checks, bug fixes: decompressor more resilient to invalid bitstreams
    • More comprehensive help page
  4. v2.4.02025-08-06 · 2025-08-06 15:47 UTC
    查看更新说明
    • Bug fixes
    • Reliability improvements: hardened decompressor against invalid bitstreams (found by fuzzing the C++ decompressor)
    • Support for 64 bits block checksum
    • Stricter UTF parsing
    • Improved LZ performance (LZ is faster and LZX is stronger)
    • Multi-stream Huffman for faster decompression
  5. v2.3.02024-05-12 · 2024-05-12 03:08 UTC
    查看更新说明
    • Bug fixes
    • Performance improvements (Huffman, ANS, ROLZ, TPAQ, ...)
    • Code cleanup (dead code removal, internal package creation, refactoring, ...)
    • New CLI options (delete source, skip dot files or links)
    • The decompressor now checks decompressed size vs original size
    • Headerless mode (via API only)

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Kanzi

    Kanzi is a modern, modular, portable, and efficient lossless data compressor written in Go.

    • Modern: Kanzi implements state-of-the-art compression algorithms and is built to fully utilize multi-core CPUs via built-in multi-threading.
    • Modular: Entropy codecs and data transforms can be selected and combined at runtime to best suit the specific data being compressed.
    • Expandable: A clean, interface-driven design—with no external dependencies—makes Kanzi easy to integrate, extend, and customize.
    • Efficient: Carefully optimized to balance compression ratio and speed for practical, high-performance usage.

    Unlike most mainstream lossless compressors, Kanzi is not limited to a single compression paradigm. By combining multiple algorithms and techniques, it supports a broader range of compression ratios and adapts better to diverse data types.

    Most traditional compressors underutilize modern hardware by running single-threaded—even on machines with many cores. Kanzi, in contrast, is concurrent by design, compressing multiple blocks in parallel across threads for significant performance gains. However, it is not compatible with standard compression formats.

    It’s important to note that Kanzi is a data compressor, not an archiver. It includes optional checksums for verifying data integrity, but does not provide features like cross-file deduplication or data recovery mechanisms. That said, it produces a seekable bitstream—meaning one or more consecutive blocks can be decompressed independently, without needing to process the entire stream.

    For more details, see Wiki, Q&A and DeepWiki

    See how to reuse the code here: https://github.com/flanglet/kanzi-go/wiki/Using-and-extending-the-code

    There is a C++ implementation available here: https://github.com/flanglet/kanzi-cpp

    There is Java implementation available here: https://github.com/flanglet/kanzi

    Build Status Quality Gate Status Lines of Code Documentation License Ask DeepWiki

    Why Kanzi

    While excellent open-source compressors like zstd and brotli exist, they are primarily based on Lempel-Ziv (LZ) algorithms. Zstd, in particular, is a fantastic general-purpose choice known for its speed. However, LZ-based tools have inherent limits regarding compression ratios.

    Kanzi offers a compelling alternative for specific high-performance scenarios:

    • Beyond LZ: By incorporating Burrows-Wheeler Transform (BWT) and Context Modeling (CM), Kanzi can achieve compression ratios that traditional LZ methods cannot.

    • Speed where it counts: While LZ is ideal for "compress once, decompress often" (like software distribution), it often slows down significantly at high compression settings. Kanzi leverages multi-core CPUs to maintain performance, making it highly effective for backups, real-time data generation, and one-off transfers.

    • Content-Aware: Kanzi features built-in, customizable transforms for specific data types (e.g., multimedia, DNA, UTF text), improving efficiency where generic compressors fail.

    • Extensible: The architecture is developer-friendly, making it straightforward to implement new transforms or entropy codecs for experimentation or niche data types.

    Benchmarks

    Kanzi version 2.6.0

    silesia.tar

    Test machine: AMD Ryzen 9950X on Ubuntu 26.04

    Go version 1.27.1

    Download at http://sun.aei.polsl.pl/~sdeor/corpus/silesia.zip

    CompressorEncoding (ms)Decoding (ms)Size
    Original211,957,760
    lz4 1.1.10 -T16 -4181379,910,851
    kanzi -l 11576979,184,957
    zstd 1.6.0 -T16 -2572569,443,247
    kanzi -l 21378468,627,321
    brotli 1.1.0 -288033368,040,160
    gzip 1.13 -91032870467,651,076
    kanzi -l 323211163,093,409
    zstd 1.6.0 -T16 -51362662,867,556
    kanzi -l 443919160,789,646
    zstd 1.6.0 -T16 -93222459,233,481
    brotli 1.1.0 -6403929958,511,709
    zstd 1.6.0 -T16 -1318202657,843,283
    brotli 1.1.0 -92303029356,407,229
    bzip2 1.0.8 -98223345354,588,597
    kanzi -l 590046253,863,205
    zstd 1.6.0 -T16 -19110902352,830,213
    kanzi -l 61295105649,472,110
    xz 5.8.1 -94361193148,802,580
    bsc 3.3.11 -T16120169847,900,848
    kanzi -l 71628118447,330,431
    bzip3 1.5.1.r3-g428f422 -j 162348221842,962,926
    kanzi -l 87597779142,962,913
    kanzi -l 9163971699141,520,677

    enwik8

    Test machine: Apple M3 24 GB Sonoma 15.7.3

    Go version 1.26.1

    Download at https://mattmahoney.net/dc/enwik8.zip

    CompressorEncoding (ms)Decoding (ms)Size
    Original100,000,000
    Kanzi -l 11695142,941,668
    Kanzi -l 21616737,688,371
    Kanzi -l 326212432,562,496
    Kanzi -l 441518329,466,291
    Kanzi -l 577641926,521,279
    Kanzi -l 6126998524,076,777
    Kanzi -l 72090167022,817,366
    Kanzi -l 87960783521,181,998
    Kanzi -l 9101041088820,035,687

    Build

    Using formal releases is recommended (see https://github.com/flanglet/kanzi-go/releases).

    go install github.com/flanglet/kanzi-go/v2/[email protected]
    

    Otherwise, to build manually from the latest tag, follow the instructions below:

    git clone https://github.com/flanglet/kanzi-go.git
    
    cd kanzi-go/v2/app
    
    go build Kanzi.go BlockCompressor.go BlockDecompressor.go InfoPrinter.go
    

    The bistream is backward compatible, however, the guarantee only applies to releases. Users can expect incompatibilities or breakage due to bitstream changes in between releases.

    Credits

    Matt Mahoney, Yann Collet, Jan Ondrus, Yuta Mori, Ilya Muravyov, Neal Burns, Fabian Giesen, Jarek Duda, Ilya Grebnov

    Disclaimer

    Use at your own risk. Always keep a copy of your original files.