compress

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 7, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CompressionGzip     = "gzip"
	CompressionIdentity = "identity"
)

Variables

This section is empty.

Functions

func Compress

func Compress(in mem.BufferSlice, compressor *CompressionPool, pool mem.BufferPool) (out mem.BufferSlice, isCompressed bool, err error)

func Decompress

func Decompress(d mem.BufferSlice, maxReceiveMessageSize int, decompressor *CompressionPool, pool mem.BufferPool) (out mem.BufferSlice, isDecompressed bool, err error)

func NegotiateCompression

func NegotiateCompression(
	availableCompressors ReadOnlyCompressionPools,
	sent, accept string,
) (requestCompression, responseCompression string, clientVisibleErr error)

NegotiateCompression determines and validates the request compression and response compression using the available compressors and protocol-specific Content-Encoding and Accept-Encoding headers.

Types

type CompressionPool

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

func NewCompressionPool

func NewCompressionPool(compressor Compressor, decompressor Decompressor) *CompressionPool

func (*CompressionPool) Compress

func (c *CompressionPool) Compress(w io.Writer) (io.WriteCloser, error)

func (*CompressionPool) Decompress

func (c *CompressionPool) Decompress(r io.Reader) (io.Reader, error)

type Compressor

type Compressor interface {
	io.Writer

	// Close flushes any buffered data to the underlying sink, then closes the
	// Compressor. It must not close the underlying sink.
	Close() error

	// Reset discards the Compressor's internal state, if any, and prepares it to
	// write compressed data to a new sink.
	Reset(io.Writer)
}

A Compressor is a reusable wrapper that compresses data written to an underlying sink. The standard library's [*gzip.Writer] implements Compressor.

type Decompressor

type Decompressor interface {
	io.Reader

	// Close closes the Decompressor, but not the underlying data source. It may
	// return an error if the Decompressor wasn't read to EOF.
	Close() error

	// Reset discards the Decompressor's internal state, if any, and prepares it
	// to read from a new source of compressed data.
	Reset(io.Reader) error
}

A Decompressor is a reusable wrapper that decompresses an underlying data source. The standard library's [*gzip.Reader] implements Decompressor.

type ReadOnlyCompressionPools

type ReadOnlyCompressionPools interface {
	Get(string) *CompressionPool
	Contains(string) bool
	// Wordy, but clarifies how this is different from readOnlyCodecs.Names().
	CommaSeparatedNames() string
}

ReadOnlyCompressionPools is a read-only interface to a map of named CompressionPools.

func NewReadOnlyCompressionPools

func NewReadOnlyCompressionPools(
	nameToPool map[string]*CompressionPool,
	reversedNames []string,
) ReadOnlyCompressionPools

Jump to

Keyboard shortcuts

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