mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 09:59:13 +08:00
address comments from PR
This commit is contained in:
@ -95,6 +95,8 @@ func BuildDagFromFile(fpath string, ds dag.DAGService, mp pin.ManualPinner) (*da
|
||||
|
||||
func BuildDagFromReader(r io.Reader, ds dag.DAGService, mp pin.ManualPinner, spl chunk.BlockSplitter) (*dag.Node, error) {
|
||||
blkChan := spl.Split(r)
|
||||
|
||||
// grab first block, it will go in the index MultiBlock (faster io)
|
||||
first := <-blkChan
|
||||
root := &dag.Node{}
|
||||
|
||||
@ -104,13 +106,14 @@ func BuildDagFromReader(r io.Reader, ds dag.DAGService, mp pin.ManualPinner, spl
|
||||
mbf.AddBlockSize(uint64(len(blk)))
|
||||
node := &dag.Node{Data: ft.WrapData(blk)}
|
||||
nk, err := ds.Add(node)
|
||||
if mp != nil {
|
||||
mp.PinWithMode(nk, pin.Indirect)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if mp != nil {
|
||||
mp.PinWithMode(nk, pin.Indirect)
|
||||
}
|
||||
|
||||
// Add a link to this node without storing a reference to the memory
|
||||
err = root.AddNodeLinkClean("", node)
|
||||
if err != nil {
|
||||
|
@ -9,11 +9,10 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
|
||||
bsrv "github.com/jbenet/go-ipfs/blockservice"
|
||||
"github.com/jbenet/go-ipfs/importer/chunk"
|
||||
dag "github.com/jbenet/go-ipfs/merkledag"
|
||||
uio "github.com/jbenet/go-ipfs/unixfs/io"
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
"github.com/jbenet/go-ipfs/util/testutil"
|
||||
)
|
||||
|
||||
// NOTE:
|
||||
@ -82,15 +81,10 @@ func testFileConsistency(t *testing.T, bs chunk.BlockSplitter, nbytes int) {
|
||||
|
||||
func TestBuilderConsistency(t *testing.T) {
|
||||
nbytes := 100000
|
||||
dstore := ds.NewMapDatastore()
|
||||
bserv, err := bsrv.NewBlockService(dstore, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dagserv := dag.NewDAGService(bserv)
|
||||
buf := new(bytes.Buffer)
|
||||
io.CopyN(buf, rand.Reader, int64(nbytes))
|
||||
io.CopyN(buf, u.NewTimeSeededRand(), int64(nbytes))
|
||||
should := dup(buf.Bytes())
|
||||
dagserv := testutil.GetDAGServ(t)
|
||||
nd, err := BuildDagFromReader(buf, dagserv, nil, chunk.DefaultSplitter)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
Reference in New Issue
Block a user