gozstd

valyalaMIT活跃维护

Go 语言封装的 zstd 压缩库,支持流式压缩和字典压缩,让 Go 程序直接调用高性能的 Zstandard 算法。

go wrapper for zstd

暂无版本482star +2 / 7 天76fork同步于 2026-11-10 11:59 UTC

怎么上手

由 README 提炼,执行前请确认
go get -u github.com/valyala/gozstd
硬件要求按 README 说明

README 未说明

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

项目说明

由 README 自动翻译提炼

Go 语言封装 zstd 压缩库,提供简单 API 和零分配高速压缩解压

Go 语言封装的 zstd 压缩库,支持流式压缩和字典压缩,让 Go 程序直接调用高性能的 Zstandard 算法。

核心能力

  • 内置上游 zstd 源码,无需额外安装依赖
  • 提供 Compress/Decompress 一行式简单 API
  • 支持零分配模式,适合高并发场景
  • 支持块/流式压缩解压及字典构建加载
  • Writer.Flush 适配网络应用场景

容易踩的坑

交叉编译需开启 CGO 并指定交叉编译器,否则会报 CDict/Writer 未定义;仓库自带 libzstd*.a 预编译文件,若与你的 OS/ARCH 不匹配需运行 make clean libzstd.a 重建;需要 go1.10 及以上版本

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

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

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

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

    README 原文

    未翻译

    Build Status GoDoc Go Report codecov

    gozstd - go wrapper for zstd

    Features

    • Vendors upstream zstd without any modifications.

    • Simple API.

    • Optimized for speed. The API may be easily used in zero allocations mode.

    • Compress* and Decompress* functions are optimized for high concurrency.

    • Proper Writer.Flush for network apps.

    • Supports the following features from upstream zstd:

      • Block / stream compression / decompression with all the supported compression levels and with dictionary support.
      • Dictionary building from a sample set. The created dictionary may be saved to persistent storage / transfered over the network.
      • Dictionary loading for compression / decompression.

      Pull requests for missing upstream zstd features are welcome.

    Quick start

    How to install gozstd?

    go get -u github.com/valyala/gozstd
    

    How to compress data?

    The easiest way is just to use Compress:

    	compressedData := Compress(nil, data)
    

    There is also StreamCompress and Writer for stream compression.

    How to decompress data?

    The easiest way is just to use Decompress:

    	data, err := Decompress(nil, compressedData)
    

    There is also StreamDecompress and Reader for stream decompression.

    How to cross-compile gozstd?

    If you're cross-compiling some code that uses gozstd and you stumble upon the following error:

    # github.com/valyala/gozstd
    /go/pkg/mod/github.com/valyala/[email protected]/stream.go:31:59: undefined: CDict
    /go/pkg/mod/github.com/valyala/[email protected]/stream.go:35:64: undefined: CDict
    /go/pkg/mod/github.com/valyala/[email protected]/stream.go:47:20: undefined: Writer
    

    You can easily fix it by enabling CGO and using a cross-compiler (e.g. arm-linux-gnueabi-gcc):

    env CC=arm-linux-gnueabi-gcc GOOS=linux GOARCH=arm CGO_ENABLED=1 go build ./main.go 
    

    NOTE: Check #21 for more info.

    Who uses gozstd?

    FAQ

    • Q: Which go version is supported? A: go1.10 and newer. Pull requests for older go versions are accepted.

    • Q: Which platforms/architectures are supported? A: linux/amd64, linux/arm, linux/arm64, linux/ppc64le, freebsd/amd64, darwin/amd64, darwin/arm64, windows/amd64. Pull requests for other platforms/architectures are accepted.

    • Q: I don't trust libzstd*.a binary files from the repo or these files dont't work on my OS/ARCH. How to rebuild them? A: Just run make clean libzstd.a if your OS/ARCH is supported.

    • Q: How do I specify custom build flags when recompiling libzstd*.a? A: You can specify MOREFLAGS=... variable when running make like this: MOREFLAGS=-fPIC make clean libzstd.a.

    • Q: Why the repo contains libzstd*.a binary files?
      A: This simplifies package installation with go get without the need to perform additional steps for building the libzstd*.a.