brotli-go.v0: gopkg.in/kothar/brotli-go.v0/enc Index | Examples | Files

package enc

import "gopkg.in/kothar/brotli-go.v0/enc"

Package enc provides Brotli encoder bindings

Index

Examples

Package Files

encode.go

func CompressBuffer Uses

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 Uses

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.

type BrotliParams Uses

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

BrotliParams describes the settings used when encoding using Brotli

Code:

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

func NewBrotliParams Uses

func NewBrotliParams() *BrotliParams

NewBrotliParams instantiates the compressor parameters with the default settings

func (*BrotliParams) Lgblock Uses

func (p *BrotliParams) Lgblock() int

Lgblock returns the current maximum input block size setting.

func (*BrotliParams) Lgwin Uses

func (p *BrotliParams) Lgwin() int

Lgwin returns the current sliding window size setting.

func (*BrotliParams) Mode Uses

func (p *BrotliParams) Mode() Mode

Mode returns the current operating mode of the compressor

func (*BrotliParams) Quality Uses

func (p *BrotliParams) Quality() int

Quality returns the quality setting of the compressor

func (*BrotliParams) SetLgblock Uses

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 Uses

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 Uses

func (p *BrotliParams) SetMode(value Mode)

SetMode controls the operating mode of the compressor (GENERIC, TEXT or FONT)

func (*BrotliParams) SetQuality Uses

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 Uses

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

BrotliWriter implements the io.Writer interface, compressing the stream to an output Writer using Brotli.

Code:

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)

func NewBrotliWriter Uses

func NewBrotliWriter(params *BrotliParams, writer io.Writer) *BrotliWriter

NewBrotliWriter instantiates a new BrotliWriter with the provided compression parameters and output Writer

func (*BrotliWriter) Close Uses

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.

func (*BrotliWriter) Write Uses

func (w *BrotliWriter) Write(buffer []byte) (int, error)

type Mode Uses

type Mode int

Mode defines the operation mode of the compressor

const (
    // GENERIC is the default compression mode. The compressor does not know anything in
    // advance about the properties of the input.
    GENERIC Mode = iota
    // TEXT is a compression mode for UTF-8 format text input.
    TEXT
    // FONT is a compression mode used in WOFF 2.0.
    FONT
)

Package enc imports 6 packages (graph) and is imported by 11 packages. Updated 2017-08-10. Refresh now. Tools for package owners.