-
Notifications
You must be signed in to change notification settings - Fork 1
/
colwriter.go
53 lines (48 loc) · 1.07 KB
/
colwriter.go
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
50
51
52
53
package giashard
import (
"log"
"path/filepath"
)
// read columns of compressed files containing lines
type ColumnWriter struct {
cols []string
writers []*LineWriter
}
// make new column reader for the given directory, which is assumed to have
// files name c1.gz, c2.gz, ... for each element of cols
func NewColumnWriter(dir string, cols ...string) (w *ColumnWriter, err error) {
writers := make([]*LineWriter, 0, len(cols))
for _, c := range cols {
lw, err := NewLineWriter(filepath.Join(dir, c + ".gz"))
if err != nil {
for _, lw := range writers {
if e := lw.Close(); e != nil {
log.Print(e)
}
}
return nil, err
}
writers = append(writers, lw)
}
w = &ColumnWriter{cols, writers}
return
}
// close the underlying readers
func (w *ColumnWriter)Close() (err error) {
for _, lw := range w.writers {
if e := lw.Close(); e != nil {
err = e
}
}
return
}
func (w *ColumnWriter)WriteRow(row map[string][]byte) (err error) {
for i, c := range(w.cols) {
e := w.writers[i].WriteLine(row[c])
if e != nil {
err = e
return
}
}
return
}