1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
[](https://godoc.org/github.com/shenwei356/xopen)
[](https://travis-ci.org/shenwei356/xopen)
[](https://coveralls.io/r/shenwei356/xopen?branch=master)
# xopen
import "github.com/shenwei356/xopen"
xopen makes it easy to get buffered (possibly `gzip`-, `xz`-, or `zstd`- compressed) readers and writers. and
close all of the associated files. `Ropen` opens a file for reading. `Wopen` opens a
file for writing.
> This packages is forked from https://github.com/brentp/xopen ,
> but I have modified too much :(
## Usage
Here's how to get a buffered reader:
```go
// gzipped
rdr, err := xopen.Ropen("some.gz")
// xz compressed
rdr, err := xopen.Ropen("some.xz")
// zstd compressed
rdr, err := xopen.Ropen("some.zst")
// normal
rdr, err := xopen.Ropen("some.txt")
// stdin (possibly gzip-, xz-, or zstd-compressed)
rdr, err := xopen.Ropen("-")
// https://
rdr, err := xopen.Ropen("http://example.com/some-file.txt")
// Cmd
rdr, err := xopen.Ropen("| ls -lh somefile.gz")
// User directory:
rdr, err := xopen.Ropen("~/shenwei356/somefile")
checkError(err)
defer checkError(rdr.Close())
```
Writter
```go
wtr, err := xopen.Wopen("some.gz")
defer checkError(wtr.Close())
outfh.Flush()
```
|