cbrotli

package module
v0.0.0-...-440e036 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2025 License: MIT Imports: 7 Imported by: 39

Documentation

Overview

Package cbrotli compresses and decompresses data with C-Brotli library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(encodedData []byte) ([]byte, error)

Decode decodes Brotli encoded data.

func DecodeWithRawDictionary

func DecodeWithRawDictionary(encodedData []byte, dictionary []byte) ([]byte, error)

DecodeWithRawDictionary decodes Brotli encoded data with shared dictionary.

func Encode

func Encode(content []byte, options WriterOptions) ([]byte, error)

Encode returns content encoded with Brotli.

Types

type DictionaryType

type DictionaryType int

DictionaryType is type for shared dictionary

const (
	// DtRaw denotes LZ77 prefix dictionary
	DtRaw DictionaryType = 0
	// DtSerialized denotes serialized format
	DtSerialized DictionaryType = 1
)

type PreparedDictionary

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

PreparedDictionary is a handle to native object.

func NewPreparedDictionary

func NewPreparedDictionary(data []byte, dictionaryType DictionaryType, quality int) *PreparedDictionary

NewPreparedDictionary prepares dictionary data for encoder. Same instance can be used for multiple encoding sessions. Close MUST be called to free resources.

func (*PreparedDictionary) Close

func (p *PreparedDictionary) Close() error

Close frees C resources. IMPORTANT: calling Close until all encoders that use that dictionary are closed as well will cause crash.

type Reader

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

Reader implements io.ReadCloser by reading Brotli-encoded data from an underlying Reader.

func NewReader

func NewReader(src io.Reader) *Reader

NewReader initializes new Reader instance. Close MUST be called to free resources.

func NewReaderWithRawDictionary

func NewReaderWithRawDictionary(src io.Reader, dictionary []byte) *Reader

NewReaderWithRawDictionary initializes new Reader instance with shared dictionary. Close MUST be called to free resources.

func (*Reader) Close

func (r *Reader) Close() error

Close implements io.Closer. Close MUST be invoked to free native resources.

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

type Writer

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

Writer implements io.WriteCloser by writing Brotli-encoded data to an underlying Writer.

func NewWriter

func NewWriter(dst io.Writer, options WriterOptions) *Writer

NewWriter initializes new Writer instance. Close MUST be called to free resources.

func (*Writer) Close

func (w *Writer) Close() error

Close flushes remaining data to the decorated writer and frees C resources.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush outputs encoded data for all input provided to Write. The resulting output can be decoded to match all input before Flush, but the stream is not yet complete until after Close. Flush has a negative impact on compression.

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Write implements io.Writer. Flush or Close must be called to ensure that the encoded bytes are actually flushed to the underlying Writer.

type WriterOptions

type WriterOptions 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
	// Prepared shared dictionary
	Dictionary *PreparedDictionary
}

WriterOptions configures Writer.

Jump to

Keyboard shortcuts

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