compressor

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 4 Imported by: 5

Documentation

Index

Constants

View Source
const (
	RatioKind  = "ratio"
	ShadowKind = "shadow"
	NoneKind   = "none"

	// CloseOverheadZlib is the number of final bytes a [zlib.Writer] call writes
	// to the output buffer.
	CloseOverheadZlib = 9
)

Variables

View Source
var KindKeys []string

Functions

func NewNonCompressor added in v1.4.2

func NewNonCompressor(config Config) (derive.Compressor, error)

NewNonCompressor creates a new derive.Compressor implementation that doesn't compress by using zlib.NoCompression. It flushes to the underlying buffer any data from a prior write call. This is very unoptimal behavior and should only be used in tests. The NonCompressor can be used in tests to create a partially flushed channel. If the output buffer size after a write exceeds TargetFrameSize*TargetNumFrames, the compressor is marked as full, but the write succeeds.

func NewRatioCompressor

func NewRatioCompressor(config Config) (derive.Compressor, error)

NewRatioCompressor creates a new derive.Compressor implementation that uses the target size and a compression ratio parameter to determine how much data can be written to the compressor before it's considered full. The full calculation is as follows:

full = uncompressedLength * approxCompRatio >= targetFrameSize * targetNumFrames

func NewShadowCompressor

func NewShadowCompressor(config Config) (derive.Compressor, error)

NewShadowCompressor creates a new derive.Compressor implementation that contains two compression buffers: one used for size estimation, and one used for the final compressed output. The first is flushed on every write, the second isn't, which means the final compressed data is always slightly smaller than the target. There is one exception to this rule: the first write to the buffer is not checked against the target, which allows individual blocks larger than the target to be included (and will be split across multiple channel frames).

Types

type Config

type Config struct {
	// TargetOutputSize is the target size that the compressed data should reach.
	// The shadow compressor guarantees that the compressed data stays below
	// this bound. The ratio compressor might go over.
	TargetOutputSize uint64
	// ApproxComprRatio to assume (only ratio compressor). Should be slightly smaller
	// than average from experiments to avoid the chances of creating a small
	// additional leftover frame.
	ApproxComprRatio float64
	// Kind of compressor to use. Must be one of KindKeys. If unset, NewCompressor
	// will default to RatioKind.
	Kind string

	// Type of compression algorithm to use. Must be one of [zlib, brotli-(9|10|11)]
	CompressionAlgo derive.CompressionAlgo
}

func (Config) NewCompressor

func (c Config) NewCompressor() (derive.Compressor, error)

type FactoryFunc

type FactoryFunc func(Config) (derive.Compressor, error)

type NonCompressor added in v1.4.2

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

func (*NonCompressor) Close added in v1.4.2

func (t *NonCompressor) Close() error

func (*NonCompressor) Flush added in v1.4.2

func (t *NonCompressor) Flush() error

func (*NonCompressor) FullErr added in v1.4.2

func (t *NonCompressor) FullErr() error

func (*NonCompressor) Len added in v1.4.2

func (t *NonCompressor) Len() int

func (*NonCompressor) Read added in v1.4.2

func (t *NonCompressor) Read(p []byte) (int, error)

func (*NonCompressor) Reset added in v1.4.2

func (t *NonCompressor) Reset()

func (*NonCompressor) Write added in v1.4.2

func (t *NonCompressor) Write(p []byte) (int, error)

type RatioCompressor

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

func (*RatioCompressor) Close

func (t *RatioCompressor) Close() error

func (*RatioCompressor) Flush

func (t *RatioCompressor) Flush() error

func (*RatioCompressor) FullErr

func (t *RatioCompressor) FullErr() error

func (*RatioCompressor) InputThreshold

func (t *RatioCompressor) InputThreshold() uint64

InputThreshold calculates the input data threshold in bytes from the given parameters.

func (*RatioCompressor) Len

func (t *RatioCompressor) Len() int

func (*RatioCompressor) Read

func (t *RatioCompressor) Read(p []byte) (int, error)

func (*RatioCompressor) Reset

func (t *RatioCompressor) Reset()

func (*RatioCompressor) Write

func (t *RatioCompressor) Write(p []byte) (int, error)

type ShadowCompressor

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

func (*ShadowCompressor) Close

func (t *ShadowCompressor) Close() error

func (*ShadowCompressor) Flush

func (t *ShadowCompressor) Flush() error

func (*ShadowCompressor) FullErr

func (t *ShadowCompressor) FullErr() error

func (*ShadowCompressor) Len

func (t *ShadowCompressor) Len() int

func (*ShadowCompressor) Read

func (t *ShadowCompressor) Read(p []byte) (int, error)

func (*ShadowCompressor) Reset

func (t *ShadowCompressor) Reset()

func (*ShadowCompressor) Write

func (t *ShadowCompressor) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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