brotli

package
v0.0.0-...-77e5a9a Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: BSD-2-Clause, MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWriter

func NewWriter(w io.Writer, level int) *pack.Writer

NewWriter returns a new pack.Writer that compresses data at the given level. Levels 0–9 are currently implemented. Levels outside this range will be replaced with the closest level available.

func Score

func Score(m pack.AbsoluteMatch) int

Types

type CompositeHasher

type CompositeHasher struct {
	A, B Hasher
}

A CompositeHasher wraps two Hashers and combines their output.

func (CompositeHasher) Candidates

func (h CompositeHasher) Candidates(dst []int, data []byte, index int) []int

func (CompositeHasher) Init

func (h CompositeHasher) Init()

func (CompositeHasher) Store

func (h CompositeHasher) Store(data []byte, index int)

type Encoder

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

An Encoder implements the pack.Encoder interface, writing in Brotli format.

func (*Encoder) Encode

func (e *Encoder) Encode(dst []byte, src []byte, matches []pack.Match, lastBlock bool) []byte

func (*Encoder) Reset

func (e *Encoder) Reset()

type H2

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

H2 is a Hasher similar to what the reference implementation of brotli uses for compression level 2.

func (*H2) Candidates

func (h *H2) Candidates(dst []int, data []byte, index int) []int

func (*H2) Init

func (h *H2) Init()

func (*H2) Store

func (h *H2) Store(data []byte, index int)

type H3

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

H3 is a Hasher similar to what the reference implementation of brotli uses for compression level 3.

func (*H3) Candidates

func (h *H3) Candidates(dst []int, data []byte, index int) []int

func (*H3) Init

func (h *H3) Init()

func (*H3) Store

func (h *H3) Store(data []byte, index int)

type H4

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

H4 is a Hasher similar to what the reference implementation of brotli uses for compression level 4.

func (*H4) Candidates

func (h *H4) Candidates(dst []int, data []byte, index int) []int

func (*H4) Init

func (h *H4) Init()

func (*H4) Store

func (h *H4) Store(data []byte, index int)

type H5

type H5 struct {
	// BlockBits is the base-2 logarithm of the number of entries per hash
	// bucket. The reference implementation sets it to one less than the
	// compression level.
	BlockBits int

	// BucketBits is the base-2 logarithm of the number of hash buckets.
	// The reference implementation sets it to 14 or 15.
	BucketBits int
	// contains filtered or unexported fields
}

H5 is a Hasher similar to what the reference implementation of brotli uses for compression levels 5–9.

func (*H5) Candidates

func (h *H5) Candidates(dst []int, data []byte, index int) []int

func (*H5) Init

func (h *H5) Init()

func (*H5) Store

func (h *H5) Store(data []byte, index int)

type H6

type H6 struct {
	// BlockBits is the base-2 logarithm of the number of entries per hash
	// bucket. The reference implementation sets it to one less than the
	// compression level.
	BlockBits int

	// BucketBits is the base-2 logarithm of the number of hash buckets.
	// The reference implementation sets it to 14 or 15.
	BucketBits int

	// HashLen is the number of bytes to hash. The reference implementation
	// normally sets it to 5.
	HashLen int
	// contains filtered or unexported fields
}

H6 is a Hasher similar to what the reference implementation of brotli uses for compression levels 5–9.

It is basically the same as H5, but with a configurable hash length.

func (*H6) Candidates

func (h *H6) Candidates(dst []int, data []byte, index int) []int

func (*H6) Init

func (h *H6) Init()

func (*H6) Store

func (h *H6) Store(data []byte, index int)

type Hasher

type Hasher interface {
	// Init allocates the Hasher's internal storage, or clears it if
	// it is already allocated. Init must be called before any of the other
	// methods.
	Init()

	// Store puts an entry in the hash table for the data at index.
	Store(data []byte, index int)

	// Candidates hashes the data at index, fetches a list of possible matches
	// from the hash table, and appends the list to dst.
	Candidates(dst []int, data []byte, index int) []int
}

A Hasher maintains a hash table for finding backreferences in data.

type M0

type M0 struct {
	// Lazy turns on "lazy matching," for higher compression but less speed.
	Lazy bool

	MaxDistance int
	MaxLength   int
}

M0 is an implementation of the pack.MatchFinder interface based on the algorithm used by snappy, but modified to be more like the algorithm used by compression level 0 of the brotli reference implementation.

func (M0) FindMatches

func (m M0) FindMatches(dst []pack.Match, src []byte) []pack.Match

FindMatches looks for matches in src, appends them to dst, and returns dst. src must not be longer than 65536 bytes.

func (M0) Reset

func (M0) Reset()

type MatchFinder

type MatchFinder struct {
	Hasher Hasher

	// MaxLength is the limit on the length of matches to find;
	// 0 means unlimited.
	MaxLength int

	// MaxDistance is the limit on the distance to look back for matches;
	// 0 means unlimited.
	MaxDistance int

	// MaxHistory is the limit on how much data from previous blocks is
	// kept around to look for matches in; 0 means that no matches from previous
	// blocks will be found.
	MaxHistory int

	// MinHistory is the amount of data that is used to start a new history
	// buffer after the size exceeds MaxHistory.
	MinHistory int
	// contains filtered or unexported fields
}

MatchFinder is an implementation of pack.MatchFinder that uses a Hasher to find matches.

func (*MatchFinder) FindMatches

func (q *MatchFinder) FindMatches(dst []pack.Match, src []byte) []pack.Match

FindMatches looks for matches in src, appends them to dst, and returns dst.

func (*MatchFinder) Reset

func (q *MatchFinder) Reset()

Jump to

Keyboard shortcuts

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