github.com/koko1123/flow-go-1@v0.29.6/network/compressor/lz4Compressor.go (about) 1 package compressor 2 3 import ( 4 "io" 5 6 "github.com/pierrec/lz4" 7 8 "github.com/koko1123/flow-go-1/network" 9 ) 10 11 var _ network.Compressor = (*Lz4Compressor)(nil) 12 13 type Lz4Compressor struct{} 14 15 func NewLz4Compressor() *Lz4Compressor { 16 return &Lz4Compressor{} 17 } 18 19 func (lz4Comp Lz4Compressor) NewReader(r io.Reader) (io.ReadCloser, error) { 20 return io.NopCloser(lz4.NewReader(r)), nil 21 } 22 23 func (lz4Comp Lz4Compressor) NewWriter(w io.Writer) (network.WriteCloseFlusher, error) { 24 return &lz4WriteCloseFlusher{w: lz4.NewWriter(w)}, nil 25 } 26 27 type lz4WriteCloseFlusher struct { 28 w *lz4.Writer 29 } 30 31 func (lz4W *lz4WriteCloseFlusher) Write(p []byte) (int, error) { 32 return lz4W.w.Write(p) 33 } 34 35 func (lz4W *lz4WriteCloseFlusher) Close() error { 36 return lz4W.w.Close() 37 } 38 39 func (lz4W *lz4WriteCloseFlusher) Flush() error { 40 return lz4W.w.Flush() 41 }