1[![GoDoc] (https://godoc.org/github.com/brentp/xopen?status.png)](https://godoc.org/github.com/brentp/xopen)
2[![Build Status](https://travis-ci.org/brentp/xopen.svg)](https://travis-ci.org/brentp/xopen)
3[![Coverage Status](https://coveralls.io/repos/brentp/xopen/badge.svg?branch=master)](https://coveralls.io/r/brentp/xopen?branch=master)
4
5# xopen
6--
7    import "github.com/brentp/xopen"
8
9xopen makes it easy to get buffered (possibly gzipped) readers and writers. and
10close all of the associated files. Ropen opens a file for reading. Wopen opens a
11file for writing. Both will use gzip when appropriate and will use buffered IO.
12
13## Usage
14
15Here's how to get a buffered reader:
16```go
17// gzipped
18rdr, err := xopen.Ropen("some.gz")
19// normal
20rdr, err := xopen.Ropen("some.txt")
21// stdin (possibly gzipped)
22rdr, err := xopen.Ropen("-")
23// https://
24rdr, err := xopen.Ropen("http://example.com/some-file.txt")
25// Cmd
26rdr, err := xopen.Ropen("|ls -lh somefile.gz")
27// User directory:
28rdr, err := xopen.Ropen("~/brentp/somefile")
29
30```
31Get a buffered writer with `xopen.Wopen`.
32
33
34#### func  CheckBytes
35
36```go
37func CheckBytes(b *bufio.Reader, buf []byte) (bool, error)
38```
39CheckBytes peeks at a buffered stream and checks if the first read bytes match.
40
41#### func  IsGzip
42
43```go
44func IsGzip(b *bufio.Reader) (bool, error)
45```
46IsGzip returns true buffered Reader has the gzip magic.
47
48#### func  IsStdin
49
50```go
51func IsStdin() bool
52```
53IsStdin checks if we are getting data from stdin.
54
55#### func  XReader
56
57```go
58func XReader(f string) (io.Reader, error)
59```
60XReader returns a reader from a url string or a file.
61
62
63#### type Reader
64
65```go
66type Reader struct {
67	*bufio.Reader
68}
69```
70
71Reader is returned by Ropen
72
73#### func  Buf
74
75```go
76func Buf(r io.Reader) *Reader
77```
78Return a buffered reader from an io.Reader If f == "-", then it will attempt to
79read from os.Stdin. If the file is gzipped, it will be read as such.
80
81#### func  Ropen
82
83```go
84func Ropen(f string) (*Reader, error)
85```
86Ropen opens a buffered reader.
87
88#### func (*Reader) Close
89
90```go
91func (r *Reader) Close() error
92```
93Close the associated files.
94
95#### type Writer
96
97```go
98type Writer struct {
99	*bufio.Writer
100}
101```
102
103Writer is returned by Wopen
104
105#### func  Wopen
106
107```go
108func Wopen(f string) (*Writer, error)
109```
110Wopen opens a buffered reader. If f == "-", then stdout will be used. If f
111endswith ".gz", then the output will be gzipped.
112
113#### func (*Writer) Close
114
115```go
116func (w *Writer) Close() error
117```
118Close the associated files.
119
120#### func (*Writer) Flush
121
122```go
123func (w *Writer) Flush()
124```
125Flush the writer.
126