compression

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2025 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCompressor = NewCompressors()

DefaultCompressor the default compressors.

Functions

This section is empty.

Types

type CompressionFormat

type CompressionFormat string

CompressionFormat represents a compression format enumeration.

const (
	// EncodingDeflate represents the deflate compression format.
	EncodingDeflate CompressionFormat = "deflate"
)
const (
	// EncodingGzip represents the gzip compression format.
	EncodingGzip CompressionFormat = "gzip"
)
const (
	// EncodingZstd represents the Zstandard compression format.
	EncodingZstd CompressionFormat = "zstd"
)

type Compressor

type Compressor interface {
	Compress(w io.Writer, src io.Reader) (int64, error)
	Decompress(reader io.ReadCloser) (io.ReadCloser, error)
}

Compressor abstracts the interface for a compression handler.

type Compressors

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

Compressors is a general helper for web compression.

func NewCompressors

func NewCompressors() *Compressors

NewCompressors create a Compressors instance.

func (Compressors) AcceptEncoding

func (c Compressors) AcceptEncoding() string

AcceptEncoding returns the Accept-Encoding header with supported compression encodings.

func (Compressors) Compress

func (c Compressors) Compress(w io.Writer, encoding string, data io.Reader) (int64, error)

Compress writes compressed data.

func (Compressors) Decompress

func (c Compressors) Decompress(reader io.ReadCloser, encoding string) (io.ReadCloser, error)

Decompress reads and decompresses the reader with equivalent the content encoding.

func (Compressors) FindSupportedEncoding

func (c Compressors) FindSupportedEncoding(encoding string) CompressionFormat

FindSupportedEncoding returns the supported encoding from the input string.

func (Compressors) IsEncodingSupported

func (c Compressors) IsEncodingSupported(encoding string) bool

IsEncodingSupported checks if the input encoding is supported.

type DeflateCompressor

type DeflateCompressor struct{}

DeflateCompressor implements the compression handler for deflate encoding.

func (DeflateCompressor) Compress

func (dc DeflateCompressor) Compress(w io.Writer, src io.Reader) (int64, error)

Compress the reader content with deflate encoding.

func (DeflateCompressor) Decompress

func (dc DeflateCompressor) Decompress(reader io.ReadCloser) (io.ReadCloser, error)

Decompress the reader content with deflate encoding.

type GzipCompressor

type GzipCompressor struct{}

GzipCompressor implements the compression handler for gzip encoding.

func (GzipCompressor) Compress

func (gc GzipCompressor) Compress(w io.Writer, src io.Reader) (int64, error)

Compress the reader content with gzip encoding.

func (GzipCompressor) Decompress

func (gc GzipCompressor) Decompress(reader io.ReadCloser) (io.ReadCloser, error)

Decompress the reader content with gzip encoding.

type ZstdCompressor

type ZstdCompressor struct{}

ZstdCompressor implements the compression handler for zstandard encoding.

func (ZstdCompressor) Compress

func (zc ZstdCompressor) Compress(w io.Writer, src io.Reader) (int64, error)

Compress the reader content with zstd encoding.

func (ZstdCompressor) Decompress

func (zc ZstdCompressor) Decompress(reader io.ReadCloser) (io.ReadCloser, error)

Decompress the reader content with zstd encoding.

Jump to

Keyboard shortcuts

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