coreapi: implement Object.Diff

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>


This commit was moved from ipfs/interface-go-ipfs-core@00f6430f32

This commit was moved from ipfs/boxo@83c279f0be
This commit is contained in:
Łukasz Magiera 2018-02-02 21:50:22 +01:00
parent 1841565f9c
commit 5dbe176f53

View File

@ -31,6 +31,39 @@ type ObjectStat struct {
CumulativeSize int
}
const (
// DiffAdd is a Type of ObjectChange where a link was added to the graph
DiffAdd = iota
// DiffRemove is a Type of ObjectChange where a link was removed from the graph
DiffRemove
// DiffMod is a Type of ObjectChange where a link was changed in the graph
DiffMod
)
// ObjectChange represents a change ia a graph
// TODO: do we want this to be an interface?
type ObjectChange struct {
// Type of the change, either:
// * DiffAdd - Added a link
// * DiffRemove - Removed a link
// * DiffMod - Modified a link
Type int
// 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.
Before Path
// After holds the link path after the change. Note that when a link is
// removed, this will be nil.
After Path
}
// ObjectAPI specifies the interface to MerkleDAG and contains useful utilities
// for manipulating MerkleDAG data structures.
type ObjectAPI interface {
@ -65,4 +98,8 @@ type ObjectAPI interface {
// SetData sets the data contained in the node
SetData(context.Context, Path, io.Reader) (ResolvedPath, error)
// Diff returns a set of changes needed to transform the first object into the
// second.
Diff(context.Context, Path, Path) ([]ObjectChange, error)
}