From d0f9d3f4e283cb7ea9fcd1acdad81a918a540b6a Mon Sep 17 00:00:00 2001 From: Justin Azoff Date: Tue, 29 Jan 2019 20:48:25 -0500 Subject: [PATCH] use PipedDecompressor for xz Native xzcat is 4x as fast --- backend/opendecompress.go | 19 ++++++------------- cmd/version.go | 2 +- go.mod | 1 - go.sum | 2 -- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/backend/opendecompress.go b/backend/opendecompress.go index dca51b2..b5dd802 100644 --- a/backend/opendecompress.go +++ b/backend/opendecompress.go @@ -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 @@ -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 @@ -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 } diff --git a/cmd/version.go b/cmd/version.go index 1bf5cd5..b789a65 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -7,7 +7,7 @@ import ( ) const ( - VERSION = "0.2.1" + VERSION = "0.2.2" ) var cmdVersion = &cobra.Command{ diff --git a/go.mod b/go.mod index f00d27d..6b1c1fe 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 607b154..6923475 100644 --- a/go.sum +++ b/go.sum @@ -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=