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 = map[AlgorithmType]Algorithm{
AlgoNone: noneAlgo{},
AlgoSnappy: snappyAlgo{},
AlgoLZ4: lz4Algo{},
}
AlgoMap maps the algorithm type to the respective Algorithm interface
var AlgoToString = map[AlgorithmType]string{
AlgoNone: "none",
AlgoSnappy: "snappy",
AlgoLZ4: "lz4",
}
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") )
var StringToAlgo = map[string]AlgorithmType{ "none": AlgoNone, "snappy": AlgoSnappy, "lz4": AlgoLZ4, }
Functions ¶
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.
func NewWriter ¶
func NewWriter(w io.Writer, algoType AlgorithmType) (*writer, error)
NewWriter returns a WriteCloser with compression support.
func Pack ¶
func Pack(data []byte, algo AlgorithmType) ([]byte, error)
Pack compresses `data` with `algo` and returns the resulting data. This is a convinience method meant to be used for small data packages.
func String ¶
func String(a AlgorithmType) 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)
func GuessAlgorithm ¶
func GuessAlgorithm(path string, header []byte) (AlgorithmType, error)
func (AlgorithmType) IsValid ¶
func (at AlgorithmType) IsValid() bool
func (AlgorithmType) String ¶
func (at AlgorithmType) String() string