Documentation
¶
Overview ¶
Package zstd provides zstd compression with two interchangeable backends:
- a CGO-accelerated backend backed by github.com/DataDog/zstd (the native libzstd) when CGO is enabled, and
- a pure-Go backend backed by github.com/klauspost/compress/zstd when CGO is disabled.
Both backends produce and consume standard zstd frames and are interoperable: data compressed by one can be decompressed by the other. Callers should import this package instead of either underlying library directly, so that a single build can target both CGO and non-CGO environments.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compress ¶
Compress compresses src at DefaultCompression. If dst is large enough it is reused, otherwise a new buffer is allocated.
Level, the compression-level constants and CompressLevel are defined in the build-tagged files (zstd_cgo.go / zstd_nocgo.go), since the level type is an alias of the active backend's native level type.
func CompressBound ¶
CompressBound returns the worst-case size needed to compress srcSize bytes. It mirrors ZSTD_COMPRESSBOUND from the zstd specification and is a valid upper bound for the output of either backend.
func CompressLevel ¶
CompressLevel compresses src at the given level using the native libzstd.
func Decompress ¶
Decompress decompresses src. If dst is large enough it is reused, otherwise a new buffer is allocated.
Types ¶
type Level ¶
type Level = int
Level is a zstd compression level. For the CGO backend it is the native libzstd integer level (1 = fastest, higher = more compression).
const ( BestSpeed Level = ddzstd.BestSpeed BestCompression Level = ddzstd.BestCompression DefaultCompression Level = ddzstd.DefaultCompression )
Compression-level constants. These re-export the native libzstd values so we never hardcode level literals ourselves.
func LevelFromInt ¶
LevelFromInt converts a standard zstd integer level (as found in Agent configuration) to a Level. For the CGO backend Level is int, so this is an identity conversion.