pierrec/lz4
GitHub: pierrec/lz4
该项目提供纯 Go 实现的 LZ4 高速压缩与解压库及命令行工具,适用于需要快速处理数据流的压缩场景。
Stars: 967 | Forks: 152
# lz4 : 纯 Go 实现的 LZ4 压缩
[](https://pkg.go.dev/github.com/pierrec/lz4/v4)
[](https://github.com/pierrec/lz4/actions)
[](https://goreportcard.com/report/github.com/pierrec/lz4)
[](https://github.com/pierrec/lz4/tags)
## 概述
这个包提供了针对 [LZ4 数据流](http://fastcompression.blogspot.fr/2013/04/lz4-streaming-format-final.html)的流式接口,以及用于 LZ4 数据块的底层压缩和解压缩函数。
该实现基于参考的 C 语言[版本](https://github.com/lz4/lz4)。
## 安装
假设你已经安装了 go 工具链:
```
go get github.com/pierrec/lz4/v4
```
这里提供了一个命令行界面工具,用于压缩和解压缩 LZ4 文件。
```
go install github.com/pierrec/lz4/v4/cmd/lz4c@latest
```
用法
```
Usage of lz4c:
-version
print the program version
Subcommands:
Compress the given files or from stdin to stdout.
compress [arguments] [ ...]
-bc
enable block checksum
-l int
compression level (0=fastest)
-sc
disable stream checksum
-size string
block max size [64K,256K,1M,4M] (default "4M")
Uncompress the given files or from stdin to stdout.
uncompress [arguments] [ ...]
```
## 示例
```
// Compress and uncompress an input string.
s := "hello world"
r := strings.NewReader(s)
// The pipe will uncompress the data from the writer.
pr, pw := io.Pipe()
zw := lz4.NewWriter(pw)
zr := lz4.NewReader(pr)
go func() {
// Compress the input string.
_, _ = io.Copy(zw, r)
_ = zw.Close() // Make sure the writer is closed
_ = pw.Close() // Terminate the pipe
}()
_, _ = io.Copy(os.Stdout, zr)
// Output:
// hello world
```
## 贡献者
感谢迄今为止所有的[贡献者](https://github.com/pierrec/lz4/graphs/contributors)!
特别感谢 [@Zariel](https://github.com/Zariel) 提供的汇编版解码器实现。
特别感谢 [@greatroar](https://github.com/greatroar) 为 amd64 和 arm64 平台提供的汇编版解码器实现。
特别感谢 [@klauspost](https://github.com/klauspost) 在代码优化方面所做的工作。
标签:EVTX分析, Go, LZ4, Ruby工具, 压缩算法, 开发库, 日志审计