Documentation
¶
Index ¶
Constants ¶
View Source
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 )
View Source
const (
// HeaderSizeThreshold is the number of bytes needed to enable compression at all.
HeaderSizeThreshold = 2048
)
Variables ¶
View Source
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") )
View Source
var ( // Whitelist of all known uncompressed formats, that would be filtered out // by the following blacklist Compressable = []string{ "image/bmp", "audio/x-wav", } // Blacklist NotCompressable = []string{ "application/ogg", "video", "audio", "image", "zip", "rar", "7z", } // Textfile extensions not covered by mime.TypeByExtension TextFileExtensions = []string{ ".go", ".json", ".yaml", ".xml", ".txt", } )
View Source
var AlgoMap = map[AlgorithmType]Algorithm{
AlgoNone: noneAlgo{},
AlgoSnappy: snappyAlgo{},
AlgoLZ4: lz4Algo{},
}
AlgoMap maps the algorithm type to the respective Algorithm interface
View Source
var AlgoToString = map[AlgorithmType]string{
AlgoNone: "none",
AlgoSnappy: "snappy",
AlgoLZ4: "lz4",
}
View Source
var ( // ErrBadAlgo is returned on a unsupported/unknown algorithm. ErrBadAlgo = errors.New("Invalid algorithm type") )
View Source
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
Click to show internal directories.
Click to hide internal directories.