...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package compress
18
19 import (
20 "io"
21
22 "github.com/golang/snappy"
23 )
24
25 type snappyCodec struct{}
26
27 func (snappyCodec) Encode(dst, src []byte) []byte {
28 return snappy.Encode(dst, src)
29 }
30
31 func (snappyCodec) EncodeLevel(dst, src []byte, _ int) []byte {
32 return snappy.Encode(dst, src)
33 }
34
35 func (snappyCodec) Decode(dst, src []byte) []byte {
36 dst, err := snappy.Decode(dst, src)
37 if err != nil {
38 panic(err)
39 }
40 return dst
41 }
42
43 func (snappyCodec) NewReader(r io.Reader) io.ReadCloser {
44 return io.NopCloser(snappy.NewReader(r))
45 }
46
47 func (snappyCodec) CompressBound(len int64) int64 {
48 return int64(snappy.MaxEncodedLen(int(len)))
49 }
50
51 func (snappyCodec) NewWriter(w io.Writer) io.WriteCloser {
52 return snappy.NewBufferedWriter(w)
53 }
54
55 func (s snappyCodec) NewWriterLevel(w io.Writer, _ int) (io.WriteCloser, error) {
56 return s.NewWriter(w), nil
57 }
58
59 func init() {
60 codecs[Codecs.Snappy] = snappyCodec{}
61 }
62
View as plain text