Documentation ¶
Index ¶
- Constants
- Variables
- func NewNonCompressor(config Config) (derive.Compressor, error)
- func NewRatioCompressor(config Config) (derive.Compressor, error)
- func NewShadowCompressor(config Config) (derive.Compressor, error)
- type Config
- type FactoryFunc
- type NonCompressor
- type RatioCompressor
- func (t *RatioCompressor) Close() error
- func (t *RatioCompressor) Flush() error
- func (t *RatioCompressor) FullErr() error
- func (t *RatioCompressor) InputThreshold() uint64
- func (t *RatioCompressor) Len() int
- func (t *RatioCompressor) Read(p []byte) (int, error)
- func (t *RatioCompressor) Reset()
- func (t *RatioCompressor) Write(p []byte) (int, error)
- type ShadowCompressor
- func (t *ShadowCompressor) Close() error
- func (t *ShadowCompressor) Flush() error
- func (t *ShadowCompressor) FullErr() error
- func (t *ShadowCompressor) Len() int
- func (t *ShadowCompressor) Read(p []byte) (int, error)
- func (t *ShadowCompressor) Reset()
- func (t *ShadowCompressor) Write(p []byte) (int, error)
Constants ¶
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 ¶
var KindKeys []string
var Kinds = map[string]FactoryFunc{ RatioKind: NewRatioCompressor, ShadowKind: NewShadowCompressor, NoneKind: NewNonCompressor, }
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) Reset ¶ added in v1.4.2
func (t *NonCompressor) Reset()
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) Reset ¶
func (t *RatioCompressor) Reset()
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) Reset ¶
func (t *ShadowCompressor) Reset()