36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
//go:build linux || freebsd
|
|||
|
|
// +build linux freebsd
|
||
|
|
|
||
|
|
package compression
|
||
|
|
|
||
|
|
import (
|
||
|
|
"compress/bzip2"
|
||
|
|
"fmt"
|
||
|
|
"io"
|
||
|
|
)
|
||
|
|
|
||
|
|
type bzip2Decompressor struct{ *BaseDecompressor }
|
||
|
|
|
||
|
|
func NewBzip2Decompressor() *bzip2Decompressor {
|
||
|
|
return &bzip2Decompressor{NewBaseDecompressor("bzip2", []string{"bzip2"}, []string{".bz2", ".tbz", ".tbz2"})}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Reader returns a bzip2 decompression reader wrapped in a NopCloser.
|
||
|
|
// compress/bzip2.NewReader returns a plain io.Reader (no Close), so we
|
||
|
|
// wrap it to satisfy the io.ReadCloser contract of the Decompressor
|
||
|
|
// interface — the bzip2 reader has no internal state that needs
|
||
|
|
// releasing.
|
||
|
|
func (b *bzip2Decompressor) Reader(r io.Reader) (io.ReadCloser, error) {
|
||
|
|
return io.NopCloser(bzip2.NewReader(r)), nil
|
||
|
|
}
|
||
|
|
|
||
|
|
type bzip2Compressor struct{ name string }
|
||
|
|
|
||
|
|
func NewBzip2Compressor() *bzip2Compressor { return &bzip2Compressor{name: "bzip2"} }
|
||
|
|
func (b *bzip2Compressor) Name() string { return b.name }
|
||
|
|
func (b *bzip2Compressor) Writer(w io.Writer) (io.WriteCloser, error) {
|
||
|
|
return nil, fmt.Errorf("bzip2 compression not supported in stdlib")
|
||
|
|
}
|
||
|
|
|
||
|
|
func init() { Register(NewBzip2Decompressor()) }
|