object.go 3.05 KB
Newer Older
1 2 3 4 5 6 7 8
package iface

import (
	"context"
	"io"

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

9 10
	ipld "gx/ipfs/QmUSyMZ8Vt4vTZr5HdDEgEfpwAXfQRuDdfCFTt7XBzhxpQ/go-ipld-format"
	cid "gx/ipfs/Qmdu2AYUV7yMoVBQPxXNfe7FJcdx16kYtsx6jAPKWQYF1y/go-cid"
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
)

// ObjectStat provides information about dag nodes
type ObjectStat struct {
	// Cid is the CID of the node
	Cid *cid.Cid

	// NumLinks is number of links the node contains
	NumLinks int

	// BlockSize is size of the raw serialized node
	BlockSize int

	// LinksSize is size of the links block section
	LinksSize int

	// DataSize is the size of data block section
	DataSize int

	// CumulativeSize is size of the tree (BlockSize + link sizes)
	CumulativeSize int
}

34 35 36
// ChangeType denotes type of change in ObjectChange
type ChangeType int

37
const (
38 39
	// DiffAdd is set when a link was added to the graph
	DiffAdd ChangeType = iota
40

41
	// DiffRemove is set when a link was removed from the graph
42 43
	DiffRemove

44
	// DiffMod is set when a link was changed in the graph
45 46 47 48 49 50 51 52 53
	DiffMod
)

// ObjectChange represents a change ia a graph
type ObjectChange struct {
	// Type of the change, either:
	// * DiffAdd - Added a link
	// * DiffRemove - Removed a link
	// * DiffMod - Modified a link
54
	Type ChangeType
55 56 57 58 59 60

	// Path to the changed link
	Path string

	// Before holds the link path before the change. Note that when a link is
	// added, this will be nil.
61
	Before ResolvedPath
62 63 64

	// After holds the link path after the change. Note that when a link is
	// removed, this will be nil.
65
	After ResolvedPath
66 67
}

68 69 70 71 72 73 74
// ObjectAPI specifies the interface to MerkleDAG and contains useful utilities
// for manipulating MerkleDAG data structures.
type ObjectAPI interface {
	// New creates new, empty (by default) dag-node.
	New(context.Context, ...options.ObjectNewOption) (ipld.Node, error)

	// Put imports the data into merkledag
75
	Put(context.Context, io.Reader, ...options.ObjectPutOption) (ResolvedPath, error)
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

	// Get returns the node for the path
	Get(context.Context, Path) (ipld.Node, error)

	// Data returns reader for data of the node
	Data(context.Context, Path) (io.Reader, error)

	// Links returns lint or links the node contains
	Links(context.Context, Path) ([]*ipld.Link, error)

	// Stat returns information about the node
	Stat(context.Context, Path) (*ObjectStat, error)

	// AddLink adds a link under the specified path. child path can point to a
	// subdirectory within the patent which must be present (can be overridden
	// with WithCreate option).
92
	AddLink(ctx context.Context, base Path, name string, child Path, opts ...options.ObjectAddLinkOption) (ResolvedPath, error)
93 94

	// RmLink removes a link from the node
95
	RmLink(ctx context.Context, base Path, link string) (ResolvedPath, error)
96 97

	// AppendData appends data to the node
98
	AppendData(context.Context, Path, io.Reader) (ResolvedPath, error)
99 100

	// SetData sets the data contained in the node
101
	SetData(context.Context, Path, io.Reader) (ResolvedPath, error)
102 103 104 105

	// Diff returns a set of changes needed to transform the first object into the
	// second.
	Diff(context.Context, Path, Path) ([]ObjectChange, error)
106
}