-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With this change in place we now decompress using Go code rather than forking off decompression programs. As a side effect, this will make it possible (although maybe not recommended) to use moar as a decompression program early in a pipeline: moar something.gz | grep hello Fixes #177, or at least what that issue has in its title.
- Loading branch information
Showing
7 changed files
with
67 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package m | ||
|
||
import ( | ||
"compress/bzip2" | ||
"compress/gzip" | ||
"io" | ||
"os" | ||
"strings" | ||
|
||
"github.com/ulikunitz/xz" | ||
) | ||
|
||
func ZOpen(filename string) (io.ReadCloser, error) { | ||
file, err := os.Open(filename) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
switch { | ||
case strings.HasSuffix(filename, ".gz"): | ||
return gzip.NewReader(file) | ||
|
||
case strings.HasSuffix(filename, ".bz2"): | ||
return struct { | ||
io.Reader | ||
io.Closer | ||
}{bzip2.NewReader(file), file}, nil | ||
|
||
case strings.HasSuffix(filename, ".xz"): | ||
xzReader, err := xz.NewReader(file) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return struct { | ||
io.Reader | ||
io.Closer | ||
}{xzReader, file}, nil | ||
} | ||
|
||
return file, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters