compress

package
v0.0.0-...-e516f66 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2016 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknown = errors.New("unknown compression format")
	ErrEmpty   = errors.New("no data to read")
)

Functions

func IsBZip2

func IsBZip2(r io.ReaderAt) (bool, error)

IsBZip2 checks to see if the received reader's contents are in bzip2 format by checking the magic numbers.

func IsGZip

func IsGZip(r io.ReaderAt) (bool, error)

IsGZip checks to see if the received reader's contents are in gzip format by checking the magic numbers.

func IsLZ4

func IsLZ4(r io.ReaderAt) (bool, error)

IsLZ4 checks to see if the received reader's contents are in LZ4 foramt by checking the magic numbers.

func IsTar

func IsTar(r io.ReaderAt) (bool, error)

IsTar checks to see if the received reader's contents are in the tar format by checking the magic numbers. This evaluates using both tar1 and tar2 magic numbers.

func IsZip

func IsZip(r io.ReaderAt) (bool, error)

IsZip checks to see if the received reader's contents are in the zip format by checking the magic numbers. This will match on zip, empty zip and spanned zip magic numbers. If you need to distinguish between those, use something else.

Types

type Format

type Format int
const (
	Unknown    Format = iota // unknown format
	GZip                     // Gzip compression format
	BZip2                    // Bzip2 compression
	LZ4                      // LZ4 compression
	Tar                      // Tar format; normally used
	Tar1                     // Tar1 magicnum format; normalizes to Tar
	Tar2                     // Tar1 magicnum format; normalizes to Tar
	Zip                      // Zip archive
	ZipEmpty                 // Empty Zip Archive
	ZipSpanned               // Spanned Zip Archive
)

func GetFormat

func GetFormat(r io.ReaderAt) (Format, error)

GetFormat tries to match up the data in the Reader to a supported magic number, if a match isn't found, UnsupportedFmt is returned

For zips, this will also match on files with empty zip or spanned zip magic numbers. If you need to distinguich between the various zip formats, use something else.

func ParseFormat

func ParseFormat(s string) Format

ParseFormat takes a string and returns the format or unknown. Any compressed tar extensions are returned as the compression format and not tar.

If the passed string starts with a '.', it is removed. All strings are lowercased

func (Format) Ext

func (f Format) Ext() string

Ext returns the extension for the format. Formats may have more than one accepted extension; alternate extensiona are not supported.

func (Format) String

func (i Format) String() string

Jump to

Keyboard shortcuts

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