brotli

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT, MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package brotli implements the Brotli reader and writer needed by external formats: WOFF2 decoding and the WeChat WASM artifact. Resource .dat packages intentionally do not use this codec.

The implementation is derived from github.com/andybalholm/brotli v1.2.1. HTTP helpers and the experimental matchfinder encoder are intentionally excluded so runtime builds do not acquire an unrelated net/http dependency.

Index

Constants

View Source
const (
	BestSpeed          = 0
	BestCompression    = 11
	DefaultCompression = 6
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

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

func NewReader

func NewReader(src io.Reader) *Reader

NewReader creates a new Reader reading the given reader.

func (*Reader) Read

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

func (*Reader) Reset

func (r *Reader) Reset(src io.Reader) error

Reset discards the Reader's state and makes it equivalent to the result of its original state from NewReader, but reading from src instead. This permits reusing a Reader rather than allocating a new one. Error is always nil

type Writer

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

func NewWriter

func NewWriter(dst io.Writer) *Writer

Writes to the returned writer are compressed and written to dst. It is the caller's responsibility to call Close on the Writer when done. Writes may be buffered and not flushed until Close.

func NewWriterLevel

func NewWriterLevel(dst io.Writer, level int) *Writer

NewWriterLevel is like NewWriter but specifies the compression level instead of assuming DefaultCompression. The compression level can be DefaultCompression or any integer value between BestSpeed and BestCompression inclusive.

func NewWriterOptions

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

NewWriterOptions is like NewWriter but specifies WriterOptions

func (*Writer) Close

func (w *Writer) Close() error

Close flushes remaining data to the decorated writer.

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) Reset

func (w *Writer) Reset(dst io.Writer)

Reset discards the Writer's state and makes it equivalent to the result of its original state from NewWriter or NewWriterLevel, but writing to dst instead. This permits reusing a Writer rather than allocating a new one.

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
}

WriterOptions configures Writer.

Jump to

Keyboard shortcuts

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