-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader.go
More file actions
33 lines (28 loc) · 712 Bytes
/
reader.go
File metadata and controls
33 lines (28 loc) · 712 Bytes
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
package csv
import (
"encoding/csv"
"os"
)
// Reader reads records from a CSV file. It is composed of a csv.Reader from
// the standard library. See it for more information on reading the CSV file.
type Reader struct {
*csv.Reader
closer func() error
}
// Open opens a CSV file for reading. If there is an error, it will be of
// type *os.PathError.
func Open(name string) (*Reader, error) {
f, err := os.Open(name)
if err != nil {
return nil, err
}
return &Reader{
Reader: csv.NewReader(f),
closer: f.Close,
}, nil
}
// Close will close the file opened by the CSV reader. The CSV contents will
// not be readable after closing the file.
func (r *Reader) Close() error {
return r.closer()
}