1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-01 07:47:07 +08:00

commands: Changed Marshaler to return a io.Reader instead of a []byte

core/commands: Refactored command marshalers
This commit is contained in:
Matt Bell
2014-12-16 04:31:13 -08:00
parent 0395a7af1e
commit fd40702f73
19 changed files with 136 additions and 85 deletions

View File

@ -3,6 +3,7 @@ package commands
import (
"bytes"
"fmt"
"io"
"path"
cmds "github.com/jbenet/go-ipfs/commands"
@ -124,7 +125,7 @@ ipfs swarm connect /ip4/104.131.131.82/tcp/4001/QmaCpDMGvV2BGHeYERUEnRQAwe3N8Szb
Type: &stringList{},
}
func stringListMarshaler(res cmds.Response) ([]byte, error) {
func stringListMarshaler(res cmds.Response) (io.Reader, error) {
list, ok := res.Output().(*stringList)
if !ok {
return nil, errors.New("failed to cast []string")
@ -132,10 +133,10 @@ func stringListMarshaler(res cmds.Response) ([]byte, error) {
var buf bytes.Buffer
for _, s := range list.Strings {
buf.Write([]byte(s))
buf.Write([]byte("\n"))
buf.WriteString(s)
buf.WriteString("\n")
}
return buf.Bytes(), nil
return &buf, nil
}
// splitAddresses is a function that takes in a slice of string peer addresses