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 ¶
const MaxCompoundDicts = 15
MaxCompoundDicts is the upper bound on compound dictionary chunks per Writer or Reader.
Variables ¶
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.
Source Files
¶
- arena.go
- assert.go
- backward_match.go
- bitwriter.go
- block_encoder.go
- block_split.go
- block_splitter.go
- cluster.go
- coderange.go
- command.go
- compound_dict.go
- compress_fragment_fast.go
- compress_fragment_fast_table15.go
- compress_fragment_two_pass.go
- compress_fragment_two_pass_table17.go
- compressor.go
- constants.go
- context_model.go
- distance_params.go
- encode_state.go
- encoder.go
- endian_little.go
- entropy_static.go
- fast_compressor.go
- fastlog.go
- fill.go
- findblocks_kernel_simd_amd64.go
- h6_scan_amd64.go
- h6b5_scan_amd64.go
- h6b5u_scan_amd64.go
- hash.go
- hash10.go
- hash2.go
- hash2u16.go
- hash3.go
- hash3u16.go
- hash4.go
- hash40.go
- hash41.go
- hash42.go
- hash4u16.go
- hash5.go
- hash54.go
- hash5b.go
- hash5b5.go
- hash5b6u16.go
- hash5b8.go
- hash6.go
- hash6b.go
- hash6b5.go
- hash6b5u.go
- hash6b8.go
- hash6u.go
- hasher_pool.go
- histogram.go
- histogram_add_simd_amd64.go
- histogram_total_count_simd_amd64.go
- huffman_block.go
- huffman_encode.go
- le_unsafe.go
- literal_cost.go
- log2.go
- matchlen.go
- matchlen_simd_amd64.go
- metablock.go
- population_cost.go
- prefetch_amd64.go
- prefix2mask_simd_amd64.go
- ringbuffer.go
- static_dict.go
- static_dict_all.go
- static_dict_lut.go
- streaming_compressor.go
- tag_mask.go
- testseeder.go
- zopfli.go
- zopfli_cost_model.go
- zopfli_hq.go
- zopfli_node.go
- zopfli_shortest_path.go