// Perform the actual add & pin locally, outputting results to reader func add(n *core.IpfsNode, reader io.Reader, useTrickle bool, chunker string) (*dag.Node, error) { chnk, err := chunk.FromString(reader, chunker) if err != nil { return nil, err } var node *dag.Node if useTrickle { node, err = importer.BuildTrickleDagFromReader( n.DAG, chnk, importer.PinIndirectCB(n.Pinning.GetManual()), ) } else { node, err = importer.BuildDagFromReader( n.DAG, chnk, importer.PinIndirectCB(n.Pinning.GetManual()), ) } if err != nil { return nil, err } return node, nil }
// TODO(cryptix): find these helpers somewhere else func (i *gatewayHandler) newDagFromReader(r io.Reader) (*dag.Node, error) { // TODO(cryptix): change and remove this helper once PR1136 is merged // return ufs.AddFromReader(i.node, r.Body) return importer.BuildDagFromReader( i.node.DAG, chunk.DefaultSplitter(r), importer.BasicPinnerCB(i.node.Pinning.GetManual())) }
func add(n *core.IpfsNode, reader io.Reader) (*merkledag.Node, error) { mp := n.Pinning.GetManual() return importer.BuildDagFromReader( n.DAG, chunk.DefaultSplitter(reader), importer.PinIndirectCB(mp), ) }
// Add builds a merkledag from the a reader, pinning all objects to the local // datastore. Returns a key representing the root node. func Add(n *core.IpfsNode, r io.Reader) (string, error) { // TODO more attractive function signature importer.BuildDagFromReader dagNode, err := importer.BuildDagFromReader( n.DAG, chunk.NewSizeSplitter(r, chunk.DefaultBlockSize), importer.BasicPinnerCB(n.Pinning.GetManual()), ) if err != nil { return "", err } k, err := dagNode.Key() if err != nil { return "", err } return k.String(), nil }