53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
//go:build linux || freebsd
|
|
// +build linux freebsd
|
|
|
|
package compression
|
|
|
|
import (
|
|
"compress/lzw"
|
|
"io"
|
|
)
|
|
|
|
const lzwLitWidth = 8
|
|
|
|
type lzwDecompressor struct {
|
|
*BaseDecompressor
|
|
order lzw.Order
|
|
}
|
|
|
|
func NewLzwDecompressor() *lzwDecompressor { return NewLzwDecompressorWithOrder(lzw.LSB) }
|
|
|
|
func NewLzwDecompressorWithOrder(order lzw.Order) *lzwDecompressor {
|
|
name := "lzw"
|
|
if order == lzw.MSB {
|
|
name = "lzw-msb"
|
|
}
|
|
return &lzwDecompressor{NewBaseDecompressor(name, []string{}, []string{".z", ".lzw"}), order}
|
|
}
|
|
|
|
func (l *lzwDecompressor) Reader(r io.Reader) (io.ReadCloser, error) {
|
|
return lzw.NewReader(r, l.order, lzwLitWidth), nil
|
|
}
|
|
|
|
type lzwCompressor struct {
|
|
name string
|
|
order lzw.Order
|
|
}
|
|
|
|
func NewLzwCompressor() *lzwCompressor { return NewLzwCompressorWithOrder(lzw.LSB) }
|
|
func NewLzwCompressorWithOrder(order lzw.Order) *lzwCompressor {
|
|
name := "lzw"
|
|
if order == lzw.MSB {
|
|
name = "lzw-msb"
|
|
}
|
|
return &lzwCompressor{name: name, order: order}
|
|
}
|
|
|
|
func (l *lzwCompressor) Name() string { return l.name }
|
|
|
|
func (l *lzwCompressor) Writer(w io.Writer) (io.WriteCloser, error) {
|
|
return lzw.NewWriter(w, l.order, lzwLitWidth), nil
|
|
}
|
|
|
|
func init() { Register(NewLzwDecompressor()) }
|