exporter initial skeleton

This commit is contained in:
David Schor 2015-08-10 01:57:25 -04:00
parent 0c3757d48e
commit 85a1bbdf0e

49
exporter/exporter.go Normal file
View file

@ -0,0 +1,49 @@
package exporter
import (
"io"
"encoding/json"
"github.com/google/cayley/graph"
)
type Exporter struct {
wr io.Writer
qstore graph.QuadStore
err error
count int32
}
func NewExporter(writer io.Writer, qstore graph.QuadStore) *Exporter {
return &Exporter{wr: writer, qstore: qstore}
}
// number of records
func (exp *Exporter) Count() int32 {
return exp.count
}
//print out the string quoted, escaped
func (exp *Exporter) WriteEscString(str string) {
var esc []byte
if exp.err != nil {
return
}
esc, exp.err = json.Marshal(str)
if exp.err != nil {
return
}
_, exp.err = exp.wr.Write(esc)
}
func (exp *Exporter) Write(str string) {
if exp.err != nil {
return
}
_, exp.err = exp.wr.Write([]byte(str))
}
func (exp *Exporter) Err() error {
return exp.err
}