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