1.4.5.2
This commit is contained in:
48
EdgeNode/internal/compressions/reader_brotli_plus.go
Normal file
48
EdgeNode/internal/compressions/reader_brotli_plus.go
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus && linux
|
||||
|
||||
package compressions
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/compressions/cbrotli"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type BrotliReader struct {
|
||||
BaseReader
|
||||
|
||||
reader *cbrotli.Reader
|
||||
}
|
||||
|
||||
func NewBrotliReader(reader io.Reader) (Reader, error) {
|
||||
return sharedBrotliReaderPool.Get(reader)
|
||||
}
|
||||
|
||||
func newBrotliReader(reader io.Reader) (Reader, error) {
|
||||
return &BrotliReader{reader: cbrotli.NewReader(reader)}, nil
|
||||
}
|
||||
|
||||
func (this *BrotliReader) Read(p []byte) (n int, err error) {
|
||||
n, err = this.reader.Read(p)
|
||||
if err != nil && strings.Contains(err.Error(), "excessive") {
|
||||
err = io.EOF
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *BrotliReader) Reset(reader io.Reader) error {
|
||||
if reader == nil {
|
||||
return nil
|
||||
}
|
||||
this.reader = cbrotli.NewReader(reader)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *BrotliReader) RawClose() error {
|
||||
return this.reader.Close()
|
||||
}
|
||||
|
||||
func (this *BrotliReader) Close() error {
|
||||
return this.Finish(this)
|
||||
}
|
||||
Reference in New Issue
Block a user