Skip to content

Commit

Permalink
use PipedDecompressor for xz
Browse files Browse the repository at this point in the history
Native xzcat is 4x as fast
  • Loading branch information
JustinAzoff committed Jan 30, 2019
1 parent d20d271 commit d0f9d3f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
19 changes: 6 additions & 13 deletions backend/opendecompress.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ import (
"path/filepath"

gzip "github.com/klauspost/pgzip"
"github.com/ulikunitz/xz"
)

//PipedDecompressor not used right now, but may come in handy
//PipedDecompressor is used to wrap higher performing native decompression tools
type PipedDecompressor struct {
io.ReadCloser
wrapped io.ReadCloser
cmd *exec.Cmd
}

func NewPipedDecompressor(f *os.File, prog string) (*PipedDecompressor, error) {
func NewPipedDecompressor(r io.ReadCloser, prog string) (*PipedDecompressor, error) {
cmd := exec.Command(prog)
cmd.Stdin = f
cmd.Stdin = r
out, err := cmd.StdoutPipe()
if err != nil {
return nil, err
Expand All @@ -31,7 +30,7 @@ func NewPipedDecompressor(f *os.File, prog string) (*PipedDecompressor, error) {
}
pd := &PipedDecompressor{
ReadCloser: out,
wrapped: f,
wrapped: r,
cmd: cmd,
}
return pd, err
Expand Down Expand Up @@ -78,14 +77,8 @@ func OpenDecompress(fn string) (r io.ReadCloser, err error) {
wrapped: f,
}, nil
case ".xz":
xzr, err := xz.NewReader(f)
if err != nil {
return nil, err
}
return &WrappedDecompressor{
ReadCloser: ioutil.NopCloser(xzr),
wrapped: f,
}, nil
xzr, err := NewPipedDecompressor(f, "xzcat")
return xzr, err
default:
return f, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

const (
VERSION = "0.2.1"
VERSION = "0.2.2"
)

var cmdVersion = &cobra.Command{
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ require (
github.com/spf13/pflag v1.0.3 // indirect
github.com/syndtr/goleveldb v0.0.0-20180128140416-211f78098806
github.com/tinylib/msgp v1.0.2
github.com/ulikunitz/xz v0.5.5
github.com/willf/bitset v1.1.9
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect
google.golang.org/appengine v1.0.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ github.com/syndtr/goleveldb v0.0.0-20180128140416-211f78098806 h1:lb1fuqOputZmuX
github.com/syndtr/goleveldb v0.0.0-20180128140416-211f78098806/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
github.com/tinylib/msgp v1.0.2 h1:DfdQrzQa7Yh2es9SuLkixqxuXS2SxsdYn0KbdrOGWD8=
github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
github.com/ulikunitz/xz v0.5.5 h1:pFrO0lVpTBXLpYw+pnLj6TbvHuyjXMfjGeCwSqCVwok=
github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/willf/bitset v1.1.9 h1:GBtFynGY9ZWZmEC9sWuu41/7VBXPFCOAbCbqTflOg9c=
github.com/willf/bitset v1.1.9/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
Expand Down

0 comments on commit d0f9d3f

Please sign in to comment.