diff --git a/commands/command.go b/commands/command.go index cf9472dc2f7c76a17cec9549006b09a20adad81e..6d165d43c9b5ef41fffcf4b57482263b006c02aa 100644 --- a/commands/command.go +++ b/commands/command.go @@ -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 { diff --git a/commands/response.go b/commands/response.go index a8b01b8db04a8f7f15aa213db478f3a307bf2a50..65f03b571ea35d7c9bd598675eb9999060b66eae 100644 --- a/commands/response.go +++ b/commands/response.go @@ -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} }