compressor

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const Name = "gzip"

Name is the name registered for the gzip compressor.

Variables

This section is empty.

Functions

func RegisterCompressor

func RegisterCompressor(c Compressor)

RegisterCompressor registers the compressor with gRPC by its name. It can be activated when sending an RPC via grpc.UseCompressor(). It will be automatically accessed when receiving a message based on the content coding header. Servers also use it to send a response with the same encoding as the request.

NOTE: this function must only be called during initialization time (i.e. in an init() function), and is not thread-safe. If multiple Compressors are registered with the same name, the one registered last will take effect.

func SetLevel

func SetLevel(level int) error

SetLevel updates the registered gzip compressor to use the compression level specified (gzip.HuffmanOnly is not supported). NOTE: this function must only be called during initialization time (i.e. in an init() function), and is not thread-safe.

The error returned will be nil if the specified level is valid.

Types

type Compressor

type Compressor interface {
	// Name is the name of the compression codec and is used to set the content
	// coding header.  The result must be static; the result cannot change
	// between calls.
	Name() string
	// Decompress reads data from r, decompresses it, and provides the
	// uncompressed data via the returned io.Reader.  If an error occurs while
	// initializing the decompressor, that error is returned instead.
	Decompress(r io.Reader) (io.Reader, error)
	// Compress writes the data written to wc to w after compressing it.  If an
	// error occurs while initializing the compressor, that error is returned
	// instead.
	Compress(w io.Writer) (io.WriteCloser, error)
}

func GetCompressor

func GetCompressor(name string) Compressor

GetCompressor returns Compressor for the given compressor name.

Jump to

Keyboard shortcuts

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