package zstdframe
import "tailscale.com/util/zstdframe"
Package zstdframe provides functionality for encoding and decoding independently compressed zstandard frames.
Index ¶
- Constants
- func AppendDecode(dst, src []byte, opts ...Option) ([]byte, error)
- func AppendEncode(dst, src []byte, opts ...Option) []byte
- func NextSize(b []byte) (n int, err error)
- type Option
Constants ¶
const ( FastestCompression = encoderLevel(zstd.SpeedFastest) DefaultCompression = encoderLevel(zstd.SpeedDefault) BetterCompression = encoderLevel(zstd.SpeedBetterCompression) BestCompression = encoderLevel(zstd.SpeedBestCompression) )
Constants that implement Option and can be passed to AppendEncode.
Functions ¶
func AppendDecode ¶
AppendDecode appends the zstandard decoded content of src to dst. The input may consist of zero or more frames. Any call that handles untrusted input should specify MaxDecodedSize.
func AppendEncode ¶
AppendEncode appends the zstandard encoded content of src to dst. It emits exactly one frame as a single segment.
func NextSize ¶
NextSize parses the next frame (regardless of whether it is a data frame or a metadata frame) and returns the total size of the frame. The frame can be skipped by slicing n bytes from b (e.g., b[n:]). It report io.ErrUnexpectedEOF if the frame is incomplete.
Types ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is an option that can be passed to AppendEncode or AppendDecode.
func EncoderLevel ¶
func EncoderLevel(level zstd.EncoderLevel) Option
EncoderLevel specifies the compression level when encoding.
This exists for compatibility with zstd.EncoderLevel values. Most usages should directly use one of the following constants:
By default, DefaultCompression is chosen. This option is ignored when decoding.
func LowMemory ¶
LowMemory specifies that the encoder and decoder should aim to use lower amounts of memory at the cost of speed. By default, more memory used for better speed.
func MaxDecodedSize ¶
MaxDecodedSize specifies the maximum decoded size and is used to protect against hostile content. By default, there is no limit. This option is ignored when encoding.
func MaxWindowSize ¶
MaxWindowSize specifies the maximum window size, which must be a power-of-two and be in the range of [zstd.MinWindowSize, zstd.MaxWindowSize].
The compression or decompression algorithm will use a LZ77 rolling window no larger than the specified size. The compression ratio will be adversely affected, but memory requirements will be lower. When decompressing, an error is reported if a LZ77 back reference exceeds the specified maximum window size.
For decompression, MaxDecodedSize is generally more useful.
func WithChecksum ¶
WithChecksum specifies whether to produce a checksum when encoding, or whether to verify the checksum when decoding. By default, checksums are produced and verified.
Source Files ¶
options.go zstd.go
- Version
- v1.84.1 (latest)
- Published
- May 29, 2025
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 1 day ago –
Tools for package owners.