Commit 7bd7ed6d authored by Matt Bell's avatar Matt Bell

commands: Added output stream field to Response

parent c0b28dc1
......@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"strings"
"io"
u "github.com/jbenet/go-ipfs/util"
)
......@@ -46,9 +47,10 @@ func (c *Command) Register(id string, sub *Command) error {
return nil
}
// Call invokes the command at the given subcommand path
func (c *Command) Call(req Request) Response {
res := NewResponse(req)
// Call invokes the command for the given Request
// Streaming output is written to `out`
func (c *Command) Call(req Request, out io.Writer) Response {
res := NewResponse(req, out)
cmds, err := c.Resolve(req.Path())
if err != nil {
......
......@@ -5,6 +5,7 @@ import (
"encoding/xml"
"fmt"
"strings"
"io"
)
// ErrorType signfies a category of errors
......@@ -59,6 +60,9 @@ type Response interface {
SetValue(interface{})
Value() interface{}
// Returns the output stream Writer
Stream() io.Writer
// Marshal marshals out the response into a buffer. It uses the EncodingType
// on the Request to chose a Marshaller (Codec).
Marshal() ([]byte, error)
......@@ -68,6 +72,7 @@ type response struct {
req Request
err *Error
value interface{}
out io.Writer
}
func (r *response) Request() Request {
......@@ -82,6 +87,10 @@ func (r *response) SetValue(v interface{}) {
r.value = v
}
func (r *response) Stream() io.Writer {
return r.out
}
func (r *response) Error() error {
if r.err == nil {
return nil
......@@ -116,6 +125,6 @@ func (r *response) Marshal() ([]byte, error) {
}
// NewResponse returns a response to match given Request
func NewResponse(req Request) Response {
return &response{req: req}
func NewResponse(req Request, out io.Writer) Response {
return &response{req: req, out: out}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment