compression

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CompressionParamLevel       = "level"
	CompressionParamMinInputLen = "minInputLen"
)

Names of compression parameters

View Source
const (
	ProviderIDZstd = 1
	ProviderIDS2   = 2
	ProviderIDLz4  = 3
)

IDs of build in compression providers

Variables

View Source
var (
	ErrMissingFooter            = fmt.Errorf("corrupted input data; cannot extract footer")
	ErrProviderNotFound         = fmt.Errorf("cannot find compression provider by ID")
	ErrCompressionParamNotFound = fmt.Errorf("cannot find compression parameter by name")
	ErrCompressionParamNotInt   = fmt.Errorf("compression parameter is not an integer type")
	ErrCompressionParamNil      = fmt.Errorf("compression parameter map cannot be nil")
)

Errors

Functions

func GetProviderID

func GetProviderID(name string) (byte, error)

Types

type CompressionParams

type CompressionParams map[string]interface{}

CompressionParams defines compression parameters used by providers

func (CompressionParams) GetInt

func (c CompressionParams) GetInt(key string) (int, error)

GetInt gets value from map and tries to parse it as integer

func (CompressionParams) GetIntWithDefault

func (c CompressionParams) GetIntWithDefault(key string, defaultValue int) (int, error)

GetIntWithDefault gets value from map and tries to parse it as integer. If key is not found in the map the dafule value is returned

type Engine

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

Engine defines compression engine

func NewEngine

func NewEngine(defaultProviderID byte, params CompressionParams) (*Engine, error)

NewEngine creates copression engine with given default provider ID If providerID == 0 it means no compression so it is returned `nil,nil`; defult not compressed buffer size - 1024 bytes Supported providers: github.com/DataDog/zstd, github.com/cloudflare/golz4, github.com/klauspost/compress/s2,

func (*Engine) AddDefaultProvider

func (ce *Engine) AddDefaultProvider(provider Provider) *Engine

AddDefaultProvider adds default compression provider

func (*Engine) AddProvider

func (ce *Engine) AddProvider(provider Provider) *Engine

AddProvider adds compression provider to the list of supported providers

func (*Engine) Compress

func (ce *Engine) Compress(input []byte) ([]byte, error)

Compress compresses input buffer using default compression provider If input buffer size < minInputSize the input is not compressed

func (*Engine) CompressWithProvider

func (ce *Engine) CompressWithProvider(input []byte, providerID byte) ([]byte, error)

CompressWithProviderinput compresses input buffer using given compression provider The compression provider must be on the list of supported providers If input buffer size < minInputSize the input is not compressed

func (*Engine) Decompress

func (ce *Engine) Decompress(input []byte) ([]byte, error)

Decompress extracts from input the information about used compression method. If compression provider is found - the data are decompressed

func (*Engine) SetDefaultProvider

func (ce *Engine) SetDefaultProvider(id byte) error

SetDefaultProvider allows to set the defult provider by ID The provider must be on the list of supported providers

func (*Engine) SetMinInputSize

func (ce *Engine) SetMinInputSize(minInputSize int) *Engine

SetMinInputSize allows to set min input buffer size. Buffers smaller than this value are not compressed

type Provider

type Provider interface {
	Compress(src []byte) ([]byte, error)
	Decompress(src []byte, dstSize int) ([]byte, error)
	GetID() byte
	Configure(params CompressionParams) error
}

Provider defines compression method

func NewLz4CompressionService

func NewLz4CompressionService() Provider

NewS2CompressionService creates new instance of compression provider which uses github.com/klauspost/compress/s2 compression method

func NewNoCompressionService

func NewNoCompressionService() Provider

NewNoCompressionService creates new instance of compression provider which is not using the compression

func NewS2CompressionService

func NewS2CompressionService() Provider

NewS2CompressionService creates new instance of compression provider which uses github.com/klauspost/compress/s2 compression method

func NewZstdCompressionService

func NewZstdCompressionService() Provider

NewZstdCompressionService creates new instance of compression provider which uses github.com/DataDog/zstd compression method

Jump to

Keyboard shortcuts

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