github.com/TeaOSLab/EdgeNode@v1.3.8/internal/compressions/reader_deflate.go (about)

     1  // Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
     2  
     3  package compressions
     4  
     5  import (
     6  	"compress/flate"
     7  	"io"
     8  )
     9  
    10  type DeflateReader struct {
    11  	BaseReader
    12  
    13  	reader io.ReadCloser
    14  }
    15  
    16  func NewDeflateReader(reader io.Reader) (Reader, error) {
    17  	return sharedDeflateReaderPool.Get(reader)
    18  }
    19  
    20  func newDeflateReader(reader io.Reader) (Reader, error) {
    21  	return &DeflateReader{reader: flate.NewReader(reader)}, nil
    22  }
    23  
    24  func (this *DeflateReader) Read(p []byte) (n int, err error) {
    25  	return this.reader.Read(p)
    26  }
    27  
    28  func (this *DeflateReader) Reset(reader io.Reader) error {
    29  	this.reader = flate.NewReader(reader)
    30  	return nil
    31  }
    32  
    33  func (this *DeflateReader) RawClose() error {
    34  	return this.reader.Close()
    35  }
    36  
    37  func (this *DeflateReader) Close() error {
    38  	return this.Finish(this)
    39  }