コード例 #1
0
ファイル: format.go プロジェクト: mohae/peu
// CompressionFormat checks to see if the data in the provided reader uses
// a supported compression format. If it does not, an UnsupportedErr is
// returned.
func CompressionFormat(r io.ReaderAt) (compress.Format, error) {
	f, err := compress.GetFormat(r)
	if err != nil {
		return compress.Unknown, err
	}
	// see if the format is a supported on
	switch f {
	case compress.GZip:
		return f, nil
	case compress.BZip2: // only decompression is supported.
		return f, nil
	case compress.LZ4:
		return f, nil
	default:
		return f, ErrUnsupported
	}
}
コード例 #2
0
ファイル: d.go プロジェクト: mohae/peu
// Decompress is the handler for decompression. The decompression format to use
// is determined by the magic bytes within the data. If no match is found, an
// ErrUnsupported is returned. Bytes read is returned along with any non io.EOF
// error that may have occurred. If the reader doesn't implement io.ReaderAt
// a panic will occur.
func Decompress(r io.Reader, w io.Writer) (int64, error) {
	a, ok := r.(io.ReaderAt)
	if !ok {
		panic("io.Reader does not implement io.ReaderAt")
	}
	f, err := compress.GetFormat(a)
	if err != nil {
		return 0, err
	}
	switch f {
	case compress.GZip:
		return DecompressGZip(r, w)
	case compress.BZip2:
		return DecompressBZip2(r, w)
	case compress.LZ4:
		return DecompressLZ4(r, w)
	default:
		return 0, ErrUnsupported
	}
}