2021-10-18 16:50:06 +08:00
|
|
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
|
|
|
|
|
|
|
|
package compressions
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/andybalholm/brotli"
|
|
|
|
|
"io"
|
2021-12-29 10:57:15 +08:00
|
|
|
"strings"
|
2021-10-18 16:50:06 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type BrotliReader struct {
|
|
|
|
|
reader *brotli.Reader
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewBrotliReader(reader io.Reader) (Reader, error) {
|
|
|
|
|
return &BrotliReader{reader: brotli.NewReader(reader)}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *BrotliReader) Read(p []byte) (n int, err error) {
|
2021-12-29 10:57:15 +08:00
|
|
|
n, err = this.reader.Read(p)
|
|
|
|
|
if err != nil && strings.Contains(err.Error(), "excessive") {
|
|
|
|
|
err = io.EOF
|
|
|
|
|
}
|
|
|
|
|
return
|
2021-10-18 16:50:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *BrotliReader) Close() error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|