rwservice.go 1.34 KB
Newer Older
Jeromy's avatar
Jeromy committed
1 2 3 4 5
package merkledag

import (
	"context"

Jeromy's avatar
Jeromy committed
6 7
	cid "github.com/ipfs/go-cid"
	ipld "github.com/ipfs/go-ipld-format"
Jeromy's avatar
Jeromy committed
8 9 10 11 12 13 14 15 16 17 18
)

// 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)

19
// Add writes a new node using the Write DAGService.
Jeromy's avatar
Jeromy committed
20 21 22 23
func (cs *ComboService) Add(ctx context.Context, nd ipld.Node) error {
	return cs.Write.Add(ctx, nd)
}

24
// AddMany adds nodes using the Write DAGService.
Jeromy's avatar
Jeromy committed
25 26 27 28
func (cs *ComboService) AddMany(ctx context.Context, nds []ipld.Node) error {
	return cs.Write.AddMany(ctx, nds)
}

29
// Get fetches a node using the Read DAGService.
Jeromy's avatar
Jeromy committed
30 31 32 33
func (cs *ComboService) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
	return cs.Read.Get(ctx, c)
}

34
// GetMany fetches nodes using the Read DAGService.
Jeromy's avatar
Jeromy committed
35 36 37 38
func (cs *ComboService) GetMany(ctx context.Context, cids []*cid.Cid) <-chan *ipld.NodeOption {
	return cs.Read.GetMany(ctx, cids)
}

39
// Remove deletes a node using the Write DAGService.
Jeromy's avatar
Jeromy committed
40 41 42 43
func (cs *ComboService) Remove(ctx context.Context, c *cid.Cid) error {
	return cs.Write.Remove(ctx, c)
}

44
// RemoveMany deletes nodes using the Write DAGService.
Jeromy's avatar
Jeromy committed
45 46 47
func (cs *ComboService) RemoveMany(ctx context.Context, cids []*cid.Cid) error {
	return cs.Write.RemoveMany(ctx, cids)
}