github.com/Psiphon-Labs/psiphon-tunnel-core@v2.0.28+incompatible/psiphon/common/quic/gquic-go/h2quic/gzipreader.go (about) 1 package h2quic 2 3 // copied from net/transport.go 4 5 // gzipReader wraps a response body so it can lazily 6 // call gzip.NewReader on the first call to Read 7 import ( 8 "compress/gzip" 9 "io" 10 ) 11 12 // call gzip.NewReader on the first call to Read 13 type gzipReader struct { 14 body io.ReadCloser // underlying Response.Body 15 zr *gzip.Reader // lazily-initialized gzip reader 16 zerr error // sticky error 17 } 18 19 func (gz *gzipReader) Read(p []byte) (n int, err error) { 20 if gz.zerr != nil { 21 return 0, gz.zerr 22 } 23 if gz.zr == nil { 24 gz.zr, err = gzip.NewReader(gz.body) 25 if err != nil { 26 gz.zerr = err 27 return 0, err 28 } 29 } 30 return gz.zr.Read(p) 31 } 32 33 func (gz *gzipReader) Close() error { 34 return gz.body.Close() 35 }