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

import (
	"fmt"
	"io"

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

Matt Bell's avatar
Matt Bell committed
11 12 13 14 15 16
var cat = &cmds.Command{
	Help: "TODO",
	Run: func(req cmds.Request, res cmds.Response) {
		node := req.Context().Node
		fmt.Println(node.Resolver)
		readers := make([]io.Reader, 0, len(req.Arguments()))
17

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

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

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

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