coreapi: dag: Missing batch docs
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Aug 3, 2018 at 18:19 UTC
d6ee9555d0e183dc574204fe5dc21bbbf4dbc017
3 files changed
+8
-1
core/coreapi/dag.go
+5
@@ -67,10 +67,14 @@ func (api *DagAPI) Tree(ctx context.Context, p coreiface.Path, opts ...caopts.Da
67
return out, nil
68
}
69
70
+// Batch creates new DagBatch
71
func (api *DagAPI) Batch(ctx context.Context) coreiface.DagBatch {
72
return &dagBatch{api: api}
73
}
74
75
+// Put inserts data using specified format and input encoding. Unless used with
76
+// `WithCodes` or `WithHash`, the defaults "dag-cbor" and "sha256" are used.
77
+// Returns the path of the inserted data.
78
func (b *dagBatch) Put(ctx context.Context, src io.Reader, opts ...caopts.DagPutOption) (coreiface.ResolvedPath, error) {
79
nd, err := getNode(src, opts...)
80
if err != nil {
@@ -84,6 +88,7 @@ func (b *dagBatch) Put(ctx context.Context, src io.Reader, opts ...caopts.DagPut
88
return coreiface.IpldPath(nd.Cid()), nil
89
}
90
91
+// Commit commits nodes to the datastore and announces them to the network
92
func (b *dagBatch) Commit(ctx context.Context) error {
93
b.lk.Lock()
94
defer b.lk.Unlock()
core/coreapi/dag_test.go
+1
-1
@@ -136,7 +136,7 @@ func TestBatch(t *testing.T) {
136
}
137
138
_, err = api.Dag().Get(ctx, c)
139
- if err == nil || err.Error() != "merkledag: not found"{
139
+ if err == nil || err.Error() != "merkledag: not found" {
140
t.Error(err)
141
}
142
core/coreapi/interface/dag.go
+2
@@ -22,6 +22,7 @@ type DagOps interface {
22
type DagBatch interface {
23
DagOps
24
25
+ // Commit commits nodes to the datastore and announces them to the network
26
Commit(ctx context.Context) error
27
}
28
@@ -35,5 +36,6 @@ type DagAPI interface {
36
// Tree returns list of paths within a node specified by the path.
37
Tree(ctx context.Context, path Path, opts ...options.DagTreeOption) ([]Path, error)
38
39
+ // Batch creates new DagBatch
40
Batch(ctx context.Context) DagBatch
41
}