6224c4be41
Further removed multiple pointer instances Re-use decompression readers (except zstd due to bugs)
35 lines
480 B
Go
35 lines
480 B
Go
package decompress
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"sync"
|
|
|
|
"github.com/therootcompany/xz"
|
|
)
|
|
|
|
type Xz struct {
|
|
pool sync.Pool
|
|
}
|
|
|
|
func NewXz() *Xz {
|
|
return &Xz{
|
|
pool: sync.Pool{
|
|
New: func() any {
|
|
rdr, _ := xz.NewReader(nil, 0)
|
|
return rdr
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (x *Xz) Decompress(data []byte) ([]byte, error) {
|
|
rdr := x.pool.Get().(*xz.Reader)
|
|
defer x.pool.Put(rdr)
|
|
err := rdr.Reset(bytes.NewReader(data))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return io.ReadAll(rdr)
|
|
}
|