6224c4be41
Further removed multiple pointer instances Re-use decompression readers (except zstd due to bugs)
31 lines
418 B
Go
31 lines
418 B
Go
package decompress
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"sync"
|
|
|
|
"github.com/pierrec/lz4/v4"
|
|
)
|
|
|
|
type Lz4 struct {
|
|
pool sync.Pool
|
|
}
|
|
|
|
func NewLz4() *Lz4 {
|
|
return &Lz4{
|
|
pool: sync.Pool{
|
|
New: func() any {
|
|
return lz4.NewReader(nil)
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (l *Lz4) Decompress(data []byte) ([]byte, error) {
|
|
rdr := l.pool.Get().(*lz4.Reader)
|
|
defer l.pool.Put(rdr)
|
|
rdr.Reset(bytes.NewReader(data))
|
|
return io.ReadAll(rdr)
|
|
}
|