encoder

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package encoder hosts the brotli streaming/fast encoder implementations and shared codec primitives consumed by the root brrr package's decoder.

Index

Constants

View Source
const MaxCompoundDicts = 15

MaxCompoundDicts is the upper bound on compound dictionary chunks per Writer or Reader.

Variables

View Source
var (
	ErrTooManyDicts  = errors.New("brrr: maximum compound dictionaries exceeded")
	ErrEmptyDict     = errors.New("brrr: empty dictionary data")
	ErrQualityTooLow = errors.New("brrr: compound dictionaries require quality >= 2")
)

Errors returned when validating compound dictionary parameters.

Functions

func SeedStreamPosForTest

func SeedStreamPosForTest(c Compressor, pos uint64) bool

SeedStreamPosForTest advances the streaming encoder's stream-position fields to pos so the next Write straddles the 32-bit wrap boundary. The ring buffer is left empty (the encoder only references data subsequently written), and lgwin caps distances so references stay within the in-metablock region.

Returns false if c is a fast (q0/q1) compressor, which does not have a streaming position concept.

Types

type Compressor

type Compressor interface {
	// Write enqueues input. Implementations may emit compressed output to dst
	// during this call (q>=2) or buffer until Flush/Close (q0/q1).
	Write(dst io.Writer, p []byte) (int, error)

	// Flush emits a non-final meta-block boundary so that everything written
	// so far is decodable from the output stream.
	Flush(dst io.Writer) error

	// Close finalizes the stream by writing the last meta-block.
	Close(dst io.Writer) error

	// ResetSizeHint clears stream state and attached dictionaries.
	// Attach dictionaries again for the next stream. A zero hint means unknown size.
	ResetSizeHint(sizeHint uint)

	// AttachDictionary attaches a compound dictionary to the encoder.
	AttachDictionary(pd *PreparedDictionary) error

	// Release returns the compressor and any owned scratch buffers to their
	// pools. The compressor must not be used after Release.
	Release()
}

Compressor writes brotli streams for one quality and window size. AttachDictionary returns an error at q0 and q1.

func NewCompressor

func NewCompressor(quality, lgwin int, sizeHint uint, parallel bool) Compressor

NewCompressor constructs a Compressor for the given quality/lgwin/sizeHint, dispatching to the appropriate backend (q0/q1 fast or q>=2 streaming) and configuring it from its pool. parallel lets q10 and q11 search matches, split blocks and cluster distances on worker goroutines.

type PreparedDictionary

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

PreparedDictionary is an immutable hash table built from caller-provided source bytes. It allows the encoder to reference those bytes as if they preceded the input stream.

Build a PreparedDictionary once with PrepareDictionary and pass it to any number of Writers via [WriterOptions.Dictionaries]. A *PreparedDictionary is safe to share across goroutines.

func PrepareDictionary

func PrepareDictionary(data []byte) (*PreparedDictionary, error)

PrepareDictionary builds an immutable PreparedDictionary from the given source bytes, suitable for use as a compound dictionary chunk via [WriterOptions.Dictionaries]. The returned dictionary may be shared across any number of Writers and goroutines.

The returned dictionary keeps a reference to data; the caller must not mutate data while any Writer holding the dictionary is still in use.

Returns an error if data is empty.

Jump to

Keyboard shortcuts

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