github.com/TeaOSLab/EdgeNode@v1.3.8/internal/compressions/reader_gzip.go (about) 1 // Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. 2 3 package compressions 4 5 import ( 6 "github.com/klauspost/compress/gzip" 7 "io" 8 ) 9 10 type GzipReader struct { 11 BaseReader 12 13 reader *gzip.Reader 14 } 15 16 func NewGzipReader(reader io.Reader) (Reader, error) { 17 return sharedGzipReaderPool.Get(reader) 18 } 19 20 func newGzipReader(reader io.Reader) (Reader, error) { 21 r, err := gzip.NewReader(reader) 22 if err != nil { 23 return nil, err 24 } 25 return &GzipReader{ 26 reader: r, 27 }, nil 28 } 29 30 func (this *GzipReader) Read(p []byte) (n int, err error) { 31 return this.reader.Read(p) 32 } 33 34 func (this *GzipReader) Reset(reader io.Reader) error { 35 return this.reader.Reset(reader) 36 } 37 38 func (this *GzipReader) RawClose() error { 39 return this.reader.Close() 40 } 41 42 func (this *GzipReader) Close() error { 43 return this.Finish(this) 44 }