File: README.md

package info (click to toggle)
golang-github-shenwei356-xopen 0.0~git20231203.5ad79ea-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 68 kB
  • sloc: makefile: 6
file content (49 lines) | stat: -rw-r--r-- 1,408 bytes parent folder | download
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
[![GoDoc](https://godoc.org/github.com/shenwei356/xopen?status.png)](https://godoc.org/github.com/shenwei356/xopen)
[![Build Status](https://travis-ci.org/shenwei356/xopen.svg)](https://travis-ci.org/shenwei356/xopen)
[![Coverage Status](https://coveralls.io/repos/shenwei356/xopen/badge.svg?branch=master)](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()
```