package
Version:
v0.23.0
Opens a new window with list of versions in this module.
Published: Oct 1, 2026
License: Apache-2.0
Opens a new window with license information.
Imports: 6
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
Documentation
¶
Package compressx 提供压缩算法注册表(roadmap 11.10-⑨ 压缩算法扩展):
- Algorithm 是压缩算法名:gzip(默认)/ zstd / brotli;Parse 对非法值报错
(不静默回退 gzip——显式语义,调用方决定 400 还是回退)。
- NewReader / NewWriter 封装三个实现(zstd 用 klauspost/compress/zstd,
brotli 用 andybalholm/brotli——均纯 Go、社区活跃、API 稳定)。
使用场景:归档(archive)压缩与存储传输的可选压缩;zstd 流**不具备** gzip 的
逐块可读性(有 frame 边界),分块传输场景须按「块级」(每 chunk 独立 frame)
组装,见 design 2026-09-24-compression-zstd.md。
NewReader 构造按算法解压的读取器。未知算法 / 构造失败返回 error。
NewWriter 构造按算法压缩的写入器(level 为压缩级别:0 = 算法默认)。
未知算法 / 非法 level 返回 error。返回的 io.WriteCloser 必须 Close 才能
完成流收尾(zstd/brotli 的 frame 尾部在 Close 时写出)。
Algorithm 是压缩算法名(gzip 默认;zstd/brotli 为扩展)。
Parse 解析压缩算法名(大小写不敏感)。非法值返回 error(不静默回退 gzip)。
ContentType 返回该算法的归档 Content-Type(gzip→application/gzip(RFC 6713),
zstd→application/zstd(RFC 8878),brotli→application/x-brotli(未注册,惯例前缀))。
Ext 返回归档文件扩展名(gzip→gz / zstd→zst / brotli→br,如 .tar.gz / .tar.zst)。
Source Files
¶
Click to show internal directories.
Click to hide internal directories.