Documentation ¶
Index ¶
- Constants
- Variables
- func GetProviderID(name string) (byte, error)
- type CompressionParams
- type Engine
- func (ce *Engine) AddDefaultProvider(provider Provider) *Engine
- func (ce *Engine) AddProvider(provider Provider) *Engine
- func (ce *Engine) Compress(input []byte) ([]byte, error)
- func (ce *Engine) CompressWithProvider(input []byte, providerID byte) ([]byte, error)
- func (ce *Engine) Decompress(input []byte) ([]byte, error)
- func (ce *Engine) SetDefaultProvider(id byte) error
- func (ce *Engine) SetMinInputSize(minInputSize int) *Engine
- type Provider
Constants ¶
const ( CompressionParamLevel = "level" CompressionParamMinInputLen = "minInputLen" )
Names of compression parameters
const ( ProviderIDZstd = 1 ProviderIDS2 = 2 ProviderIDLz4 = 3 )
IDs of build in compression providers
Variables ¶
var ( 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 ¶
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 ¶
AddDefaultProvider adds default compression provider
func (*Engine) AddProvider ¶
AddProvider adds compression provider to the list of supported providers
func (*Engine) Compress ¶
Compress compresses input buffer using default compression provider If input buffer size < minInputSize the input is not compressed
func (*Engine) CompressWithProvider ¶
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 ¶
Decompress extracts from input the information about used compression method. If compression provider is found - the data are decompressed
func (*Engine) SetDefaultProvider ¶
SetDefaultProvider allows to set the defult provider by ID The provider must be on the list of supported providers
func (*Engine) SetMinInputSize ¶
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