压缩
ling-base common/compress 模块文档
在线 Playground
在浏览器中直接体验本页相关 API,无需本地安装 Go 环境。
compress
Compression and decompression utilities supporting multiple algorithms.
Supported algorithms
Gzip, Zlib, Flate/Deflate, Zstd, Snappy (block format), LZ4 (frame format).
Key types
Algorithm-- algorithm identifier (AlgGzip,AlgZstd,AlgSnappy,AlgLZ4, ...)- Compression level constants:
LevelNone,LevelBest,LevelFastest,LevelDefault
Key functions
GzipCompress(data, level)/GzipDecompress(data)ZlibCompress(data, level)/ZlibDecompress(data)FlateCompress(data, level)/FlateDecompress(data)ZstdCompress(data)/ZstdDecompress(data)SnappyCompress(data)/SnappyDecompress(data)LZ4Compress(data)/LZ4Decompress(data)NewGzipWriter(w, level)/NewGzipReader(r)-- streaming helpers
Quick start
import "github.com/LingByte/ling-base/common/compress"
data := []byte("hello world hello world hello world")
compressed, err := compress.GzipCompress(data, compress.LevelBest)
if err != nil {
log.Fatal(err)
}
decompressed, err := compress.GzipDecompress(compressed)
if err != nil {
log.Fatal(err)
}License
MIT