compress

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2018 License: AGPL-3.0 Imports: 16 Imported by: 0

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

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,
}
View Source
var (
	// Textfile extensions not covered by mime.TypeByExtension
	TextFileExtensions = map[string]bool{
		".go":   true,
		".json": true,
		".yaml": true,
		".xml":  true,
		".txt":  true,
	}
)

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

func Unpack

func Unpack(data []byte) ([]byte, error)

Unpack unpacks `data` and returns the decompressed data. The algorithm is read from the data itself. This is a convinience method meant to be used for small data packages.

Types

type Algorithm

type Algorithm interface {
	Encode([]byte) ([]byte, error)
	Decode([]byte) ([]byte, error)
}

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

Jump to

Keyboard shortcuts

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