cat.go 814 Bytes
Newer Older
1 2 3 4 5
package commands

import (
	"io"

Matt Bell's avatar
Matt Bell committed
6
	cmds "github.com/jbenet/go-ipfs/commands"
7
	uio "github.com/jbenet/go-ipfs/unixfs/io"
8 9
)

10
var catCmd = &cmds.Command{
11 12 13
	Arguments: []cmds.Argument{
		cmds.Argument{"object", cmds.ArgString, false, true},
	},
Matt Bell's avatar
Matt Bell committed
14
	Help: "TODO",
15
	Run: func(res cmds.Response, req cmds.Request) {
Matt Bell's avatar
Matt Bell committed
16 17
		node := req.Context().Node
		readers := make([]io.Reader, 0, len(req.Arguments()))
18

19 20
		for _, arg := range req.Arguments() {
			path := arg.(string)
Matt Bell's avatar
Matt Bell committed
21 22 23 24 25
			dagnode, err := node.Resolver.ResolvePath(path)
			if err != nil {
				res.SetError(err, cmds.ErrNormal)
				return
			}
26

Matt Bell's avatar
Matt Bell committed
27 28 29 30 31 32 33
			read, err := uio.NewDagReader(dagnode, node.DAG)
			if err != nil {
				res.SetError(err, cmds.ErrNormal)
				return
			}

			readers = append(readers, read)
34
		}
Matt Bell's avatar
Matt Bell committed
35 36 37 38

		reader := io.MultiReader(readers...)
		res.SetValue(reader)
	},
39
}