-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjsonl_writer.go
38 lines (29 loc) · 893 Bytes
/
jsonl_writer.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
package ratchet_processors
import (
"io"
"github.com/licaonfee/ratchet/data"
"github.com/licaonfee/ratchet/processors"
"github.com/licaonfee/ratchet/util"
)
type JSONLWriter struct {
writer io.Writer
}
// Assert JSONLWriter satisfies the interface processors.DataProcessor
var _ processors.DataProcessor = &JSONLWriter{}
// NewJSONLWriter returns a new JSONLWriter wrapping the given io.Writer object
func NewJSONLWriter(w io.Writer) *JSONLWriter {
return &JSONLWriter{
writer: w,
}
}
func (w *JSONLWriter) ProcessData(d data.JSON, outputChan chan data.JSON, killChan chan error) {
_, err := w.writer.Write(d)
util.KillPipelineIfErr(err, killChan)
_, err = w.writer.Write([]byte("\n"))
util.KillPipelineIfErr(err, killChan)
}
func (w *JSONLWriter) Finish(outputChan chan data.JSON, killChan chan error) {
}
func (w *JSONLWriter) String() string {
return "JSONLWriter"
}