Documentation ¶
Index ¶
Constants ¶
const ( // AlgoNone represents a ,,uncompressed” algorithm. AlgoNone = iota // AlgoSnappy represents the snappy compression algorithm: // https://en.wikipedia.org/wiki/Snappy_(software) AlgoSnappy //AlgoLZ4 represents the lz4 compression algorithm: // https://en.wikipedia.org/wiki/LZ4_(compression_algorithm) AlgoLZ4 )
const (
// HeaderSizeThreshold is the number of bytes needed to enable compression at all.
HeaderSizeThreshold = 2048
)
Variables ¶
var ( // ErrBadIndex is returned on invalid compression index. ErrBadIndex = errors.New("Broken compression index") // ErrHeaderTooSmall is returned if the header is less than 10 bytes. // It usually indicates a broken file or a non-compressed file. ErrHeaderTooSmall = errors.New("Header is less than 10 bytes") // ErrBadMagicNumber is returned if the first 8 bytes of the stream is not // the expected "elchwald". ErrBadMagicNumber = errors.New("Bad magic number in compressed stream") // ErrBadAlgorithm is returned when the algorithm was either not present // or it had an invalid value ErrBadAlgorithm = errors.New("Invalid algorithm") // ErrUnsupportedVersion is returned when we don't have a reader that // understands that format. ErrUnsupportedVersion = errors.New("Version of this format is not supported") )
var ( // AlgoMap is a map of available algorithms. AlgoMap = map[AlgorithmType]Algorithm{ AlgoNone: noneAlgo{}, AlgoSnappy: snappyAlgo{}, AlgoLZ4: lz4Algo{}, } )
var CompressibleMapping = map[string]bool{}/* 636 elements not displayed */
CompressibleMapping maps between mime types and a bool indicating if they're compressible. Choice of Algorithm comes later.
This was converted from this mime db: https://cdn.rawgit.com/jshttp/mime-db/master/db.json
var ( // ErrBadAlgo is returned on a unsupported/unknown algorithm. ErrBadAlgo = errors.New("Invalid algorithm type") )
Functions ¶
func AlgoToString ¶
func AlgoToString(a AlgorithmType) string
AlgoToString converts a algorithm type to a string.
Types ¶
type Algorithm ¶
Algorithm is the common interface for all supported algorithms.
func AlgorithmFromType ¶
func AlgorithmFromType(a AlgorithmType) (Algorithm, error)
AlgorithmFromType returns a interface to the given AlgorithmType.
type AlgorithmType ¶
type AlgorithmType byte
AlgorithmType user defined type to store the algorithm type.
func AlgoFromString ¶
func AlgoFromString(s string) (AlgorithmType, error)
AlgoFromString tries to convert a string to AlgorithmType
func GuessAlgorithm ¶
func GuessAlgorithm(path string, header []byte) (AlgorithmType, error)
GuessAlgorithm takes the path name and the header data of it and tries to guess a suitable compression algorithm.
func (AlgorithmType) IsValid ¶
func (at AlgorithmType) IsValid() bool
IsValid returns true if `at` is a valid algorithm type.
func (AlgorithmType) String ¶
func (at AlgorithmType) String() string
type Reader ¶ added in v0.2.0
type Reader struct {
// contains filtered or unexported fields
}
Reader implements an decompressing reader
func NewReader ¶
func NewReader(r io.ReadSeeker) *Reader
NewReader returns a new ReadSeeker with compression support. As random access is the purpose of this layer, a ReadSeeker is required as parameter. The used compression algorithm is chosen based on trailer information.
type Writer ¶ added in v0.2.0
type Writer struct {
// contains filtered or unexported fields
}
Writer implements a compression writer.
func NewWriter ¶
func NewWriter(w io.Writer, algoType AlgorithmType) (*Writer, error)
NewWriter returns a WriteCloser with compression support.
func (*Writer) Close ¶ added in v0.2.0
Close cleans up internal resources. Make sure to call close always since it might write data.