/
encoder.go
53 lines (41 loc) · 939 Bytes
/
encoder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package lzw
import (
"compress/lzw"
"io"
"github.com/pkg/errors"
"github.com/mickep76/compress"
)
type encoder struct {
writer io.WriteCloser
order int
litWidth int
}
func (a *algorithm) NewEncoder(w io.Writer, opts ...compress.EncoderOption) (compress.Encoder, error) {
e := &encoder{
litWidth: 8,
}
for _, opt := range opts {
if err := opt(e); err != nil {
return nil, err
}
}
e.writer = lzw.NewWriter(w, lzw.Order(e.order), e.litWidth)
return e, nil
}
func (e *encoder) SetLevel(level compress.Level) error {
return errors.Wrap(compress.ErrUnsupportedOption, "algorithm lzw")
}
func (e *encoder) SetEndian(endian compress.Endian) error {
e.order = int(endian)
return nil
}
func (e *encoder) SetLitWidth(width int) error {
e.litWidth = width
return nil
}
func (e *encoder) Write(v []byte) (int, error) {
return e.writer.Write(v)
}
func (e *encoder) Close() error {
return e.writer.Close()
}