compression

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: Apache-2.0, Apache-2.0 Imports: 10 Imported by: 1

README

This package has been taken from github.com/containers/image and adjusted to provide an algorithn interface instead of an internal struct. It also transparently support an None compression.

Documentation

Index

Constants

View Source
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.)

View Source
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.)

View Source
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.)

View Source
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

View Source
var Bzip2 = NewAlgorithm(Bzip2AlgorithmName, Bzip2AlgorithmName,
	[]byte{0x42, 0x5A, 0x68}, bzip2Decompressor, bzip2Compressor)

Bzip2 compression.

View Source
var Gzip = NewAlgorithm(GzipAlgorithmName, GzipAlgorithmName,
	[]byte{0x1F, 0x8B, 0x08}, gzipDecompressor, gzipCompressor)
View Source
var None = NewAlgorithm("none", "", nil, noneDecompressor, noneCompressor)
View Source
var Xz = NewAlgorithm(XzAlgorithmName, XzAlgorithmName,
	[]byte{0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00}, xzDecompressor, xzCompressor)

Xz compression.

View Source
var Zstd = NewAlgorithm(ZstdAlgorithmName, ZstdAlgorithmName,
	[]byte{0x28, 0xb5, 0x2f, 0xfd}, ZstdDecompressor, zstdCompressor)

Zstd compression.

Functions

func AutoDecompress

func AutoDecompress(stream io.Reader) (io.ReadCloser, bool, error)

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 NewMatchReader(r io.Reader) *matchReader

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 Register

func Register(algo Algorithm)

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

func AlgorithmByName(name string) (Algorithm, error)

AlgorithmByName returns the compressor by its name.

func DetectCompression

func DetectCompression(input io.Reader) (Algorithm, io.Reader, error)

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

type CompressorFunc func(io.Writer, map[string]string, *int) (io.WriteCloser, error)

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!).

type MatchReader

type MatchReader interface {
	io.Reader
	Reset()
}

Jump to

Keyboard shortcuts

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