coreapi unixfs: Simpler output handling
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Sep 20, 2018 at 17:02 UTC
c056e5a8dee4f7e36c2a077fbd2fc49f938ed541
1 file changed
+6
-21
core/coreapi/unixfs.go
+6
-21
@@ -10,11 +10,10 @@ import (
10
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
11
"github.com/ipfs/go-ipfs/core/coreunix"
12
13
- cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
13
+ uio "gx/ipfs/QmPL8bYtbACcSFFiSr4s2du7Na382NxRADR8hC7D9FkEA2/go-unixfs/io"
14
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
15
cidutil "gx/ipfs/QmQJSeE3CX4zos9qeaG8EhecEK9zvrTEfTG84J8C5NVRwt/go-cidutil"
16
"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit/files"
17
- uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
17
dag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
18
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
19
)
@@ -60,20 +59,17 @@ func (api *UnixfsAPI) Add(ctx context.Context, r io.ReadCloser, opts ...options.
59
prefix.MhType = settings.MhType
60
prefix.MhLength = -1
61
63
- outChan := make(chan interface{}, 1)
64
-
62
fileAdder, err := coreunix.NewAdder(ctx, api.node.Pinning, api.node.Blockstore, api.node.DAG)
63
if err != nil {
64
return nil, err
65
}
66
70
- fileAdder.Out = outChan
67
fileAdder.Chunker = settings.Chunker
68
//fileAdder.Progress = progress
69
//fileAdder.Hidden = hidden
70
//fileAdder.Wrap = wrap
71
//fileAdder.Pin = dopin
76
- fileAdder.Silent = false
72
+ fileAdder.Silent = true
73
fileAdder.RawLeaves = settings.RawLeaves
74
//fileAdder.NoCopy = nocopy
75
//fileAdder.Name = pathName
@@ -100,24 +96,13 @@ func (api *UnixfsAPI) Add(ctx context.Context, r io.ReadCloser, opts ...options.
96
return nil, err
97
}
98
103
- if _, err = fileAdder.Finalize(); err != nil {
99
+ nd, err := fileAdder.Finalize()
100
+ if err != nil {
101
return nil, err
102
}
103
107
- for {
108
- select {
109
- case r := <-outChan:
110
- output := r.(*coreunix.AddedObject)
111
- if output.Hash != "" {
112
- c, err := cid.Parse(output.Hash)
113
- if err != nil {
114
- return nil, err
115
- }
116
-
117
- return coreiface.IpfsPath(c), err
118
- }
119
- }
120
- }
104
+ return coreiface.IpfsPath(nd.Cid()), err
105
+
106
}
107
108
// Cat returns the data contained by an IPFS or IPNS object(s) at path `p`.