compress

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package compress wraps zstd/lz4 block compression and defines the composable codec-chain type (preprocessor → general compressor) used to reach 0.4–0.8 bytes/point (DESIGN.md §3.3, §14 M0).

A [Chain] is a sequence of a column-specific preprocessor (from [chunk]) followed by a general compressor (ZSTD or LZ4). Cold-tier recompression is just a different chain over the same parts. The wrappers are append-style (Compress(dst, src) []byte / Decompress(dst, src) []byte) and use pooled encoders/ decoders to avoid per-call allocation.

Index

Constants

View Source
const (
	// FlagRaw means the payload is stored uncompressed.
	FlagRaw byte = 0x00
	// FlagCompressed means the payload is algorithm-compressed.
	FlagCompressed byte = 0x01
)

Flag bytes for the compressed-block format.

Variables

This section is empty.

Functions

This section is empty.

Types

type Algorithm

type Algorithm uint8

Algorithm identifies a general-purpose compression algorithm.

const (
	// AlgorithmNone is the identity (no compression).
	AlgorithmNone Algorithm = iota
	// AlgorithmZSTD is Zstandard (high ratio, good speed; default for cold data).
	AlgorithmZSTD
	// AlgorithmLZ4 is LZ4 (fast, lower ratio; default for hot data).
	AlgorithmLZ4
)

func (Algorithm) String

func (a Algorithm) String() string

String returns a stable lower-case algorithm name.

type Compressor

type Compressor struct {
	// contains filtered or unexported fields
}

Compressor is a pooled, append-style compressor. It is safe for concurrent use (each Compress/Decompress call borrows a pooled encoder/decoder).

func NewCompressor

func NewCompressor(alg Algorithm, level Level) *Compressor

NewCompressor returns a Compressor for the given algorithm and level. Level is only meaningful for ZSTD; LZ4 ignores it.

func (*Compressor) Algorithm

func (c *Compressor) Algorithm() Algorithm

Algorithm returns the compressor's algorithm.

func (*Compressor) Compress

func (c *Compressor) Compress(dst, src []byte) []byte

Compress appends the compressed form of src to dst and returns the extended slice. If compression does not reduce the size (rare for small inputs), the raw bytes are stored with a 1-byte prefix FlagRaw.

func (*Compressor) Decompress

func (c *Compressor) Decompress(dst, src []byte) ([]byte, error)

Decompress appends the decompressed form of src to dst and returns the extended slice. src must start with a flag byte (FlagRaw or FlagCompressed).

type Level

type Level uint8

Level is a compression level. ZSTD levels: 1–22 (default 3, higher = better ratio but slower). LZ4 levels are not exposed (LZ4 is always fastest).

const (
	// LevelDefault is the default compression level per algorithm.
	LevelDefault Level = 0
	// LevelFast is the fastest compression (ZSTD 1, LZ4 default).
	LevelFast Level = 1
	// LevelBest is the best ratio (ZSTD 19, LZ4 default).
	LevelBest Level = 19
)

Jump to

Keyboard shortcuts

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