9fb4f8839d
The original module `github.com/xi2/xz/` is in the Public Domain but does not explicitly specify a license. The module has not been updated since 2017. The fork at `github.com/therootcompany/xz` simply adds a Creative Commons CC0 1.0 Universal (CC0-1.0) license declaration for Public Domain use. However, this license has been disallowed by Fedora since 2022, as announced in the [Fedora Legal thread](https://lists.fedoraproject.org/archives/list/legal@lists.fedoraproject.org/thread/RRYM3CLYJYW64VSQIXY6IF3TCDZGS6LM/#EO4JUQRG4GDLRHJHJBUZDR2RHMXNU5HT), and the restriction also applies to RHEL and related distributions. The module at `github.com/mikelolasagasti/xz` is a fork of `xi2/xz`, but declares the BSD Zero Clause License (0BSD) instead. This aligns with the licensing of the upstream source from which `xi2/xz` originally derives, which has moved from [Public Domain to 0BSD for recent updates](https://tukaani.org/xz/embedded.html#_licensing). Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
35 lines
481 B
Go
35 lines
481 B
Go
package decompress
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"sync"
|
|
|
|
"github.com/mikelolasagasti/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)
|
|
}
|