add.go 586 B

123456789101112131415161718192021222324252627
  1. package embeddedShell
  2. import (
  3. "io"
  4. "gopkg.in/errgo.v1"
  5. "github.com/ipfs/go-ipfs/importer"
  6. "github.com/ipfs/go-ipfs/importer/chunk"
  7. )
  8. func (s *Shell) Add(r io.Reader) (string, error) {
  9. dag, err := importer.BuildDagFromReader(
  10. s.node.DAG,
  11. chunk.DefaultSplitter(r),
  12. importer.BasicPinnerCB(s.node.Pinning.GetManual()), // TODO: make pinning configurable
  13. )
  14. if err != nil {
  15. return "", errgo.Notef(err, "add: importing DAG failed.")
  16. }
  17. k, err := dag.Key()
  18. if err != nil {
  19. return "", errgo.Notef(err, "add: getting key from DAG failed.")
  20. }
  21. return k.B58String(), nil
  22. }