github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/compressor/gzipCompressor.go (about) 1 package compressor 2 3 import ( 4 "compress/gzip" 5 "io" 6 7 "github.com/onflow/flow-go/network" 8 ) 9 10 type GzipStreamCompressor struct{} 11 12 func (gzipStreamComp GzipStreamCompressor) NewReader(r io.Reader) (io.ReadCloser, error) { 13 return gzip.NewReader(r) 14 } 15 16 func (gzipStreamComp GzipStreamCompressor) NewWriter(w io.Writer) (network.WriteCloseFlusher, error) { 17 return &gzipWriteCloseFlusher{w: gzip.NewWriter(w)}, nil 18 } 19 20 type gzipWriteCloseFlusher struct { 21 w *gzip.Writer 22 } 23 24 func (gzipW *gzipWriteCloseFlusher) Write(p []byte) (int, error) { 25 return gzipW.w.Write(p) 26 } 27 28 func (gzipW *gzipWriteCloseFlusher) Close() error { 29 return gzipW.w.Close() 30 } 31 32 func (gzipW *gzipWriteCloseFlusher) Flush() error { 33 return gzipW.w.Flush() 34 }