enc

package
v0.0.0-...-3f28d64 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2019 License: MIT Imports: 7 Imported by: 11

Documentation

Overview

Package enc provides Brotli encoder bindings

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompressBuffer

func CompressBuffer(input []byte, options *BrotliWriterOptions) ([]byte, error)

CompressBuffer compresses a single block of data. Default options are used if options is nil. Returns the brotli-compressed version of the data, or an error.

Types

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(compressedWriter, nil)
// 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(dst io.Writer, options *BrotliWriterOptions) *BrotliWriter

NewBrotliWriter instantiates a new BrotliWriter that writes with dst, and configured with the passed options (which may be nil)

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.

func (*BrotliWriter) Write

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

type BrotliWriterOptions

type BrotliWriterOptions struct {
	// Quality controls the compression-speed vs compression-density trade-offs.
	// The higher the quality, the slower the compression. Range is 0 to 11.
	Quality int

	// LGWin is the base 2 logarithm of the sliding window size.
	// Range is 10 to 24. 0 indicates automatic configuration based on Quality.
	LGWin int
}

BrotliWriterOptions configures BrotliWriter

Example
var input []byte

compressed, _ := CompressBuffer(input, &BrotliWriterOptions{
	// brotli supports quality values from 0 to 11 included
	// 0 is the fastest, 11 is the most compressed but slowest
	Quality: 0,
})
_ = compressed
Output:

Jump to

Keyboard shortcuts

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