diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-11-15 21:39:40 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-11-15 21:39:40 -0500 |
commit | efc7a5ebc9e10983571c080017100a8b39eee1d0 (patch) | |
tree | b11aea0aaefb6c16521b2433338ebe7d0440de14 /frontend.go | |
parent | 7675ebe9567bd7cae4306f484e3677bf88ba8b55 (diff) |
more
Diffstat (limited to 'frontend.go')
-rw-r--r-- | frontend.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/frontend.go b/frontend.go new file mode 100644 index 0000000..73f6d73 --- /dev/null +++ b/frontend.go @@ -0,0 +1,68 @@ +package libfastimport + +import ( + "io" + "bufio" + + "git.lukeshu.com/go/libfastimport/textproto" +) + +type Frontend struct { + w *bufio.Writer + fiw *textproto.FIWriter + cbr *textproto.CatBlobReader +} + +func NewFrontend(w io.Writer, r io.Reader) *Frontend { + ret := Frontend{} + ret.w = bufio.NewWriter(w) + ret.fiw = textproto.NewFIWriter(ret.w) + if r != nil { + ret.cbr = textproto.NewCatBlobReader(r) + } + return &ret +} + +func (f *Frontend) Do(cmd Cmd) error { + err := cmd.fiWriteCmd(f.fiw) + if err != nil { + return err + } + return f.w.Flush() +} + +func (f *Frontend) GetMark(cmd CmdGetMark) (string, error) { + err := f.Do(cmd) + if err != nil { + return "", err + } + line, err := f.cbr.ReadLine() + if err != nil { + return "", err + } + return cbpGetMark(line) +} + +func (f *Frontend) CatBlob(cmd CmdCatBlob) (sha1 string, data string, err error) { + err = f.Do(cmd) + if err != nil { + return "", "", err + } + line, err := f.cbr.ReadLine() + if err != nil { + return "", "", err + } + return cbpCatBlob(line) +} + +func (f *Frontend) Ls(cmd CmdLs) (mode textproto.Mode, dataref string, path textproto.Path, err error) { + err = f.Do(cmd) + if err != nil { + return 0, "", "", err + } + line, err := f.cbr.ReadLine() + if err != nil { + return 0, "", "", err + } + return cbpLs(line) +} |