forked from ETHFSx/go-merkledag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rwservice.go
47 lines (37 loc) · 1.34 KB
/
rwservice.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package merkledag
import (
"context"
cid "github.com/ipfs/go-cid"
ipld "github.com/ipfs/go-ipld-format"
)
// ComboService implements ipld.DAGService, using 'Read' for all fetch methods,
// and 'Write' for all methods that add new objects.
type ComboService struct {
Read ipld.NodeGetter
Write ipld.DAGService
}
var _ ipld.DAGService = (*ComboService)(nil)
// Add writes a new node using the Write DAGService.
func (cs *ComboService) Add(ctx context.Context, nd ipld.Node) error {
return cs.Write.Add(ctx, nd)
}
// AddMany adds nodes using the Write DAGService.
func (cs *ComboService) AddMany(ctx context.Context, nds []ipld.Node) error {
return cs.Write.AddMany(ctx, nds)
}
// Get fetches a node using the Read DAGService.
func (cs *ComboService) Get(ctx context.Context, c cid.Cid) (ipld.Node, error) {
return cs.Read.Get(ctx, c)
}
// GetMany fetches nodes using the Read DAGService.
func (cs *ComboService) GetMany(ctx context.Context, cids []cid.Cid) <-chan *ipld.NodeOption {
return cs.Read.GetMany(ctx, cids)
}
// Remove deletes a node using the Write DAGService.
func (cs *ComboService) Remove(ctx context.Context, c cid.Cid) error {
return cs.Write.Remove(ctx, c)
}
// RemoveMany deletes nodes using the Write DAGService.
func (cs *ComboService) RemoveMany(ctx context.Context, cids []cid.Cid) error {
return cs.Write.RemoveMany(ctx, cids)
}