dag.go 1.17 KB
Newer Older
1 2 3 4 5 6
package iface

import (
	"context"
	"io"

7
	"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
8

Steven Allen's avatar
Steven Allen committed
9
	ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
10 11
)

12 13
// DagOps groups operations that can be batched together
type DagOps interface {
14 15 16
	// Put inserts data using specified format and input encoding.
	// Unless used with WithCodec or WithHash, the defaults "dag-cbor" and
	// "sha256" are used.
17
	Put(ctx context.Context, src io.Reader, opts ...options.DagPutOption) (ResolvedPath, error)
18 19 20 21 22 23 24
}

// DagBatch is the batching version of DagAPI. All implementations of DagBatch
// should be threadsafe
type DagBatch interface {
	DagOps

25
	// Commit commits nodes to the datastore and announces them to the network
26 27 28 29 30 31
	Commit(ctx context.Context) error
}

// DagAPI specifies the interface to IPLD
type DagAPI interface {
	DagOps
32 33 34 35 36 37

	// Get attempts to resolve and get the node specified by the path
	Get(ctx context.Context, path Path) (ipld.Node, error)

	// Tree returns list of paths within a node specified by the path.
	Tree(ctx context.Context, path Path, opts ...options.DagTreeOption) ([]Path, error)
38

39
	// Batch creates new DagBatch
40
	Batch(ctx context.Context) DagBatch
41
}