This commit is contained in:
unknown
2026-02-04 20:27:13 +08:00
commit 3b042d1dad
9410 changed files with 1488147 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
// 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"
)
const (
BrotliBestSpeed = 0
BrotliBestCompression = 11
BrotliDefaultLGWin = 14
)
type BrotliWriter struct {
BaseWriter
writer *cbrotli.Writer
level int
}
func NewBrotliWriter(writer io.Writer, level int) (Writer, error) {
return sharedBrotliWriterPool.Get(writer, level)
}
func newBrotliWriter(writer io.Writer) (*BrotliWriter, error) {
var level = GenerateCompressLevel(BrotliBestSpeed, BrotliBestCompression)
return &BrotliWriter{
writer: cbrotli.NewWriter(writer, cbrotli.WriterOptions{
Quality: level,
LGWin: BrotliDefaultLGWin,
}),
level: level,
}, nil
}
func (this *BrotliWriter) Write(p []byte) (int, error) {
return this.writer.Write(p)
}
func (this *BrotliWriter) Flush() error {
return this.writer.Flush()
}
func (this *BrotliWriter) Reset(newWriter io.Writer) {
_ = this.writer.Close()
if newWriter == nil {
return
}
this.writer = cbrotli.NewWriter(newWriter, cbrotli.WriterOptions{
Quality: this.level,
LGWin: BrotliDefaultLGWin,
})
}
func (this *BrotliWriter) RawClose() error {
return this.writer.Close()
}
func (this *BrotliWriter) Close() error {
return this.Finish(this)
}
func (this *BrotliWriter) Level() int {
return this.level
}