github.com/wfusion/gofusion@v1.1.14/common/utils/compress/wrapper.go (about) 1 package compress 2 3 import ( 4 "io" 5 6 "github.com/klauspost/compress/flate" 7 "github.com/klauspost/compress/gzip" 8 "github.com/klauspost/compress/s2" 9 "github.com/klauspost/compress/zlib" 10 ) 11 12 type s2Decodable struct { 13 *s2.Reader 14 } 15 16 func (s *s2Decodable) Read(p []byte) (n int, err error) { return s.Reader.Read(p) } 17 func (s *s2Decodable) Reset(r io.Reader) (err error) { s.Reader.Reset(r); return } 18 19 type gzipDecodable struct { 20 io.ReadCloser 21 } 22 23 func (g *gzipDecodable) Read(p []byte) (n int, err error) { return g.ReadCloser.Read(p) } 24 func (g *gzipDecodable) Reset(r io.Reader) (err error) { g.ReadCloser, err = gzip.NewReader(r); return } 25 26 type deflateDecodable struct { 27 io.ReadCloser 28 } 29 30 func (d *deflateDecodable) Read(p []byte) (n int, err error) { return d.ReadCloser.Read(p) } 31 func (d *deflateDecodable) Reset(r io.Reader) (err error) { d.ReadCloser = flate.NewReader(r); return } 32 33 type zlibDecodable struct { 34 io.ReadCloser 35 } 36 37 func (z *zlibDecodable) Read(p []byte) (n int, err error) { return z.ReadCloser.Read(p) } 38 func (z *zlibDecodable) Reset(r io.Reader) (err error) { z.ReadCloser, err = zlib.NewReader(r); return }