Documentation
¶
Overview ¶
Package enc provides Brotli encoder bindings
Index ¶
- func CompressBuffer(params *BrotliParams, inputBuffer []byte, encodedBuffer []byte) ([]byte, error)
- func CompressBufferDict(params *BrotliParams, inputBuffer []byte, inputDict []byte, ...) ([]byte, error)
- type BrotliParams
- func (p *BrotliParams) Lgblock() int
- func (p *BrotliParams) Lgwin() int
- func (p *BrotliParams) Mode() Mode
- func (p *BrotliParams) Quality() int
- func (p *BrotliParams) SetLgblock(value int)
- func (p *BrotliParams) SetLgwin(value int)
- func (p *BrotliParams) SetMode(value Mode)
- func (p *BrotliParams) SetQuality(value int)
- type BrotliWriter
- type Mode
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompressBuffer ¶
func CompressBuffer(params *BrotliParams, inputBuffer []byte, encodedBuffer []byte) ([]byte, error)
CompressBuffer compresses a single block of data. It uses encodedBuffer as the destination buffer unless it is too small, in which case a new buffer is allocated. Default parameters are used if params is nil. Returns the slice of the encodedBuffer containing the output, or an error.
func CompressBufferDict ¶
func CompressBufferDict(params *BrotliParams, inputBuffer []byte, inputDict []byte, encodedBuffer []byte) ([]byte, error)
CompressBufferDict compresses a single block of data using a custom dictionary. It uses encodedBuffer as the destination buffer unless it is too small, in which case a new buffer is allocated. Default parameters are used if params is nil. Returns the slice of the encodedBuffer containing the output, or an error.
Types ¶
type BrotliParams ¶
type BrotliParams struct {
// contains filtered or unexported fields
}
BrotliParams describes the settings used when encoding using Brotli
Example ¶
var input []byte params := NewBrotliParams() // brotli supports quality values from 0 to 11 included // 0 is the fastest, 11 is the most compressed but slowest params.SetQuality(0) compressed, _ := CompressBuffer(params, input, make([]byte, 0)) _ = compressed
Output:
func NewBrotliParams ¶
func NewBrotliParams() *BrotliParams
NewBrotliParams instantiates the compressor parameters with the default settings
func (*BrotliParams) Lgblock ¶
func (p *BrotliParams) Lgblock() int
Lgblock returns the current maximum input block size setting.
func (*BrotliParams) Lgwin ¶
func (p *BrotliParams) Lgwin() int
Lgwin returns the current sliding window size setting.
func (*BrotliParams) Mode ¶
func (p *BrotliParams) Mode() Mode
Mode returns the current operating mode of the compressor
func (*BrotliParams) Quality ¶
func (p *BrotliParams) Quality() int
Quality returns the quality setting of the compressor
func (*BrotliParams) SetLgblock ¶
func (p *BrotliParams) SetLgblock(value int)
SetLgblock sets the base 2 logarithm of the maximum input block size. Range is 16 to 24. If set to 0 (default), the value will be set based on the quality.
func (*BrotliParams) SetLgwin ¶
func (p *BrotliParams) SetLgwin(value int)
SetLgwin sets the base 2 logarithm of the sliding window size. Range is 10 to 24. Default is 22.
func (*BrotliParams) SetMode ¶
func (p *BrotliParams) SetMode(value Mode)
SetMode controls the operating mode of the compressor (GENERIC, TEXT or FONT)
func (*BrotliParams) SetQuality ¶
func (p *BrotliParams) SetQuality(value int)
SetQuality controls the compression-speed vs compression-density tradeoffs. The higher the quality, the slower the compression. Range is 0 to 11. Default is 11.
type BrotliWriter ¶
type BrotliWriter struct {
// contains filtered or unexported fields
}
BrotliWriter implements the io.Writer interface, compressing the stream to an output Writer using Brotli.
Example ¶
compressedWriter, _ := os.OpenFile("data.bin.bro", os.O_CREATE|os.O_WRONLY, 0644) brotliWriter := NewBrotliWriter(nil, compressedWriter) // BrotliWriter will close writer passed as argument if it implements io.Closer defer brotliWriter.Close() fileReader, _ := os.Open("data.bin") defer fileReader.Close() io.Copy(brotliWriter, fileReader)
Output:
func NewBrotliWriter ¶
func NewBrotliWriter(params *BrotliParams, writer io.Writer) *BrotliWriter
NewBrotliWriter instantiates a new BrotliWriter with the provided compression parameters and output Writer
func (*BrotliWriter) Close ¶
func (w *BrotliWriter) Close() error
Close cleans up the resources used by the Brotli encoder for this stream. If the output buffer is an io.Closer, it will also be closed.