项目仍在开发中,API 不稳定且可能存在 bug;压缩速度和体积目前比不上官方 xz 工具;gxz 压缩后会替换原文件为 .xz 文件,注意备份
xz
ulikunitz活跃维护纯 Go 实现的 xz 压缩格式读写库,不依赖 CGO 或外部命令,方便在 Go 程序里直接解压和生成 .xz 文件。
Pure golang package for reading and writing xz-compressed files
go get github.com/ulikunitz/xz/cmd/gxzREADME 未说明,纯 Go 实现不涉及特定 GPU 或显存要求
纯 Go 实现的 xz 压缩读写库,让 Go 程序无需 C 依赖即可处理 xz 流
纯 Go 实现的 xz 压缩格式读写库,不依赖 CGO 或外部命令,方便在 Go 程序里直接解压和生成 .xz 文件。
核心能力
- 用纯 Go 实现 xz 流的读写,不依赖任何 C 代码
- 提供 xz.NewWriter 和 xz.NewReader 两个 API 做压缩解压
- 附带 gxz 命令行工具,可直接压缩和解压文件
- 不受原 xz 供应链攻击 CVE-2024-3094 影响
容易踩的坑
暂无 release 数据(可能没有发版,或尚未同步)。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Package xz
This Go language package supports the reading and writing of xz compressed streams. It includes also a gxz command for compressing and decompressing data. The package is completely written in Go and doesn't have any dependency on any C code.
The package is currently under development. There might be bugs and APIs are not considered stable. At this time the package cannot compete with the xz tool regarding compression speed and size. The algorithms there have been developed over a long time and are highly optimized. However there are a number of improvements planned and I'm very optimistic about parallel compression and decompression. Stay tuned!
Using the API
The following example program shows how to use the API.
package main
import (
"bytes"
"io"
"log"
"os"
"github.com/ulikunitz/xz"
)
func main() {
const text = "The quick brown fox jumps over the lazy dog.\n"
var buf bytes.Buffer
// compress text
w, err := xz.NewWriter(&buf)
if err != nil {
log.Fatalf("xz.NewWriter error %s", err)
}
if _, err := io.WriteString(w, text); err != nil {
log.Fatalf("WriteString error %s", err)
}
if err := w.Close(); err != nil {
log.Fatalf("w.Close error %s", err)
}
// decompress buffer and write output to stdout
r, err := xz.NewReader(&buf)
if err != nil {
log.Fatalf("NewReader error %s", err)
}
if _, err = io.Copy(os.Stdout, r); err != nil {
log.Fatalf("io.Copy error %s", err)
}
}
Documentation
You can find the full documentation at pkg.go.dev.
Using the gxz compression tool
The package includes a gxz command line utility for compression and decompression.
Use following command for installation:
$ go get github.com/ulikunitz/xz/cmd/gxz
To test it call the following command.
$ gxz bigfile
After some time a much smaller file bigfile.xz will replace bigfile. To decompress it use the following command.
$ gxz -d bigfile.xz
Security & Vulnerabilities
The security policy is documented in SECURITY.md.
The software is not affected by the supply chain attack on the original xz implementation, CVE-2024-3094. This implementation doesn't share any files with the original xz implementation and no patches or pull requests are accepted without a review.
All security advisories for this project are published under github.com/ulikunitz/xz/security/advisories.