Documentation ¶
Index ¶
- Constants
- Variables
- func AutoDecompress(stream io.Reader) (io.ReadCloser, bool, error)
- func NewMatchReader(r io.Reader) *matchReader
- func NopWriteCloser(w io.Writer) io.WriteCloser
- func Register(algo Algorithm)
- func ZstdDecompressor(r io.Reader) (io.ReadCloser, error)
- type Algorithm
- type CompressorFunc
- type DecompressorFunc
- type MatchReader
Constants ¶
const Bzip2AlgorithmName = "bzip2"
Bzip2AlgorithmName is the name used by pkg/compression.Bzip2. NOTE: Importing only this /types package does not inherently guarantee a Bzip2 algorithm will actually be available. (In fact it is intended for this types package not to depend on any of the implementations.)
const GzipAlgorithmName = "gzip"
GzipAlgorithmName is the name used by pkg/compression.Gzip. NOTE: Importing only this /types package does not inherently guarantee a Gzip algorithm will actually be available. (In fact it is intended for this types package not to depend on any of the implementations.)
const XzAlgorithmName = "Xz"
XzAlgorithmName is the name used by pkg/compression.Xz. NOTE: Importing only this /types package does not inherently guarantee a Xz algorithm will actually be available. (In fact it is intended for this types package not to depend on any of the implementations.)
const ZstdAlgorithmName = "zstd"
ZstdAlgorithmName is the name used by pkg/compression.Zstd. NOTE: Importing only this /types package does not inherently guarantee a Zstd algorithm will actually be available. (In fact it is intended for this types package not to depend on any of the implementations.)
Variables ¶
var Bzip2 = NewAlgorithm(Bzip2AlgorithmName, Bzip2AlgorithmName, []byte{0x42, 0x5A, 0x68}, bzip2Decompressor, bzip2Compressor)
Bzip2 compression.
var Gzip = NewAlgorithm(GzipAlgorithmName, GzipAlgorithmName, []byte{0x1F, 0x8B, 0x08}, gzipDecompressor, gzipCompressor)
var None = NewAlgorithm("none", "", nil, noneDecompressor, noneCompressor)
var Xz = NewAlgorithm(XzAlgorithmName, XzAlgorithmName, []byte{0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00}, xzDecompressor, xzCompressor)
Xz compression.
var Zstd = NewAlgorithm(ZstdAlgorithmName, ZstdAlgorithmName, []byte{0x28, 0xb5, 0x2f, 0xfd}, ZstdDecompressor, zstdCompressor)
Zstd compression.
Functions ¶
func AutoDecompress ¶
AutoDecompress takes a stream and returns an uncompressed version of the same stream. The caller must call Close() on the returned stream (even if the input does not need, or does not even support, closing!).
func NewMatchReader ¶
func NopWriteCloser ¶
func NopWriteCloser(w io.Writer) io.WriteCloser
NopWriteCloser returns a ReadCloser with a no-op Close method wrapping the provided Reader r.
func ZstdDecompressor ¶
func ZstdDecompressor(r io.Reader) (io.ReadCloser, error)
ZstdDecompressor is a DecompressorFunc for the zstd compression algorithm.
Types ¶
type Algorithm ¶
type Algorithm interface { Name() string Compressor(io.Writer, map[string]string, *int) (io.WriteCloser, error) Decompressor(io.Reader) (io.ReadCloser, error) Match(MatchReader) (bool, error) }
Algorithm is a compression algorithm provided and supported by pkg/compression. It can’t be supplied from the outside.
func AlgorithmByName ¶
AlgorithmByName returns the compressor by its name.
func DetectCompression ¶
DetectCompression returns an Algorithm if the input is recognized as a compressed format, an invalid value and nil otherwise. Because it consumes the start of input, other consumers must use the returned io.Reader instead to also read from the beginning.
func NewAlgorithm ¶
func NewAlgorithm(name, mime string, prefix []byte, decompressor DecompressorFunc, compressor CompressorFunc) Algorithm
NewAlgorithm creates an Algorithm instance. This function exists so that Algorithm instances can only be created by code that is allowed to import this internal subpackage.
type CompressorFunc ¶
CompressorFunc writes the compressed stream to the given writer using the specified compression level. The caller must call Close() on the stream (even if the input stream does not need closing!).
type DecompressorFunc ¶
type DecompressorFunc func(io.Reader) (io.ReadCloser, error)
DecompressorFunc returns the decompressed stream, given a compressed stream. The caller must call Close() on the decompressed stream (even if the compressed input stream does not need closing!).