object.go 3.06 KB
Newer Older
1 2 3 4
package iface

import (
	"context"
Łukasz Magiera's avatar
Łukasz Magiera committed
5
	path "github.com/ipfs/interface-go-ipfs-core/path"
6 7
	"io"

Łukasz Magiera's avatar
Łukasz Magiera committed
8
	"github.com/ipfs/interface-go-ipfs-core/options"
9

Łukasz Magiera's avatar
Łukasz Magiera committed
10
	"github.com/ipfs/go-cid"
Łukasz Magiera's avatar
Łukasz Magiera committed
11
	ipld "github.com/ipfs/go-ipld-format"
12 13 14 15 16
)

// ObjectStat provides information about dag nodes
type ObjectStat struct {
	// Cid is the CID of the node
17
	Cid cid.Cid
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

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

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

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

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

45
	// DiffMod is set when a link was changed in the graph
46 47 48 49 50 51 52 53 54
	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
55
	Type ChangeType
56 57 58 59 60 61

	// 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.
62
	Before path.Resolved
63 64 65

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

69 70 71 72 73 74 75
// 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
76
	Put(context.Context, io.Reader, ...options.ObjectPutOption) (path.Resolved, error)
77 78

	// Get returns the node for the path
Łukasz Magiera's avatar
Łukasz Magiera committed
79
	Get(context.Context, path.Path) (ipld.Node, error)
80 81

	// Data returns reader for data of the node
Łukasz Magiera's avatar
Łukasz Magiera committed
82
	Data(context.Context, path.Path) (io.Reader, error)
83 84

	// Links returns lint or links the node contains
Łukasz Magiera's avatar
Łukasz Magiera committed
85
	Links(context.Context, path.Path) ([]*ipld.Link, error)
86 87

	// Stat returns information about the node
Łukasz Magiera's avatar
Łukasz Magiera committed
88
	Stat(context.Context, path.Path) (*ObjectStat, error)
89 90 91 92

	// 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).
93
	AddLink(ctx context.Context, base path.Path, name string, child path.Path, opts ...options.ObjectAddLinkOption) (path.Resolved, error)
94 95

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

	// AppendData appends data to the node
99
	AppendData(context.Context, path.Path, io.Reader) (path.Resolved, error)
100 101

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

	// Diff returns a set of changes needed to transform the first object into the
	// second.
Łukasz Magiera's avatar
Łukasz Magiera committed
106
	Diff(context.Context, path.Path, path.Path) ([]ObjectChange, error)
107
}