cat.go 749 B

1234567891011121314151617181920212223242526272829
  1. package embeddedShell
  2. import (
  3. "io"
  4. "gopkg.in/errgo.v1"
  5. "github.com/ipfs/go-ipfs/core"
  6. "github.com/ipfs/go-ipfs/path"
  7. unixfsio "github.com/ipfs/go-ipfs/unixfs/io"
  8. )
  9. // Cat resolves the ipfs path p and returns a reader for that data, if it exists and is availalbe
  10. func (s *Shell) Cat(p string) (io.ReadCloser, error) {
  11. ipfsPath, err := path.ParsePath(p)
  12. if err != nil {
  13. return nil, errgo.Notef(err, "cat: could not parse %q", p)
  14. }
  15. nd, err := core.Resolve(s.ctx, s.node, ipfsPath)
  16. if err != nil {
  17. return nil, errgo.Notef(err, "cat: could not resolve %s", ipfsPath)
  18. }
  19. dr, err := unixfsio.NewDagReader(s.ctx, nd, s.node.DAG)
  20. if err != nil {
  21. return nil, errgo.Notef(err, "cat: failed to construct DAG reader")
  22. }
  23. return dr, nil
  24. }