zstdframe

package
v1.66.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package zstdframe provides functionality for encoding and decoding independently compressed zstandard frames.

Index

Constants

View Source
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.

Variables

This section is empty.

Functions

func AppendDecode

func AppendDecode(dst, src []byte, opts ...Option) ([]byte, error)

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

func AppendEncode(dst, src []byte, opts ...Option) []byte

AppendEncode appends the zstandard encoded content of src to dst. It emits exactly one frame as a single segment.

func NextSize

func NextSize(b []byte) (n int, err error)

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

func LowMemory(low bool) Option

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

func MaxDecodedSize(maxSize uint64) Option

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

func MaxWindowSize(maxSize uint64) Option

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

func WithChecksum(check bool) Option

WithChecksum specifies whether to produce a checksum when encoding, or whether to verify the checksum when decoding. By default, checksums are produced and verified.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL