Documentation
¶
Overview ¶
Package compression provides unified compression/decompression utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutoDecompress ¶
AutoDecompress automatically detects compression type and decompresses data.
Types ¶
type Closeable ¶
type Closeable interface {
Close()
}
Closeable is an optional interface for compressors that hold resources.
type Compressor ¶
type Compressor interface {
// Compress compresses the input data
Compress(data []byte) ([]byte, error)
// Decompress decompresses the input data
Decompress(data []byte) ([]byte, error)
// Type returns the compression type
Type() Type
// Name returns the human-readable name of the compressor
Name() string
}
Compressor provides a unified interface for compression operations.
func Default ¶
func Default() Compressor
Default returns the default compressor (zstd with default level). Falls back to gzip if zstd initialization fails.
type GzipCompressor ¶
type GzipCompressor struct {
// contains filtered or unexported fields
}
GzipCompressor implements Compressor using gzip.
func NewGzipCompressor ¶
func NewGzipCompressor(level Level) *GzipCompressor
NewGzipCompressor creates a new gzip compressor.
func (*GzipCompressor) Compress ¶
func (c *GzipCompressor) Compress(data []byte) ([]byte, error)
Compress compresses data using gzip.
func (*GzipCompressor) Decompress ¶
func (c *GzipCompressor) Decompress(data []byte) ([]byte, error)
Decompress decompresses gzip data.
type NoOpCompressor ¶
type NoOpCompressor struct{}
NoOpCompressor is a pass-through compressor that does not compress data.
func NewNoOpCompressor ¶
func NewNoOpCompressor() *NoOpCompressor
NewNoOpCompressor creates a new no-op compressor.
func (*NoOpCompressor) Compress ¶
func (c *NoOpCompressor) Compress(data []byte) ([]byte, error)
Compress returns the data unchanged.
func (*NoOpCompressor) Decompress ¶
func (c *NoOpCompressor) Decompress(data []byte) ([]byte, error)
Decompress returns the data unchanged.
type Type ¶
type Type uint8
Type represents the compression algorithm used.
func DetectType ¶
DetectType detects the compression type from magic bytes. Returns TypeGzip for gzip (0x1f 0x8b), TypeZstd for zstd (0x28 0xb5 0x2f 0xfd).
type ZstdCompressor ¶
type ZstdCompressor struct {
// contains filtered or unexported fields
}
ZstdCompressor implements Compressor using zstd.
func NewZstdCompressor ¶
func NewZstdCompressor(level Level) (*ZstdCompressor, error)
NewZstdCompressor creates a new zstd compressor. The compressor is reusable and thread-safe for encoding.
func (*ZstdCompressor) Close ¶
func (c *ZstdCompressor) Close()
Close releases resources used by the compressor.
func (*ZstdCompressor) Compress ¶
func (c *ZstdCompressor) Compress(data []byte) ([]byte, error)
Compress compresses data using zstd.
func (*ZstdCompressor) Decompress ¶
func (c *ZstdCompressor) Decompress(data []byte) ([]byte, error)
Decompress decompresses zstd data.