mantaray

package
v0.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2021 License: BSD-3-Clause Imports: 11 Imported by: 4

Documentation

Index

Constants

View Source
const (
	PathSeparator = '/' // path separator
)

Variables

View Source
var (
	// ErrTooShort too short input
	ErrTooShort = errors.New("serialised input too short")
	// ErrInvalid input to seralise invalid
	ErrInvalid = errors.New("input invalid")
	// ErrForkIvalid shows embedded node on a fork has no reference
	ErrForkIvalid = errors.New("fork node without reference")
)
View Source
var (
	ErrNotFound         = errors.New("not found")
	ErrEmptyPath        = errors.New("empty path")
	ErrMetadataTooLarge = errors.New("metadata too large")
)

Error used when lookup path does not match

View Source
var (
	// ErrNoSaver saver interface not given
	ErrNoSaver = errors.New("Node is not persisted but no saver")
	// ErrNoLoader saver interface not given
	ErrNoLoader = errors.New("Node is reference but no loader")
)
View Source
var (
	ZeroObfuscationKey []byte
)

Functions

func SetObfuscationKeyFn added in v0.3.3

func SetObfuscationKeyFn(fn func([]byte) (int, error))

SetObfuscationKeyFn allows configuring custom function for generating obfuscation key.

NOTE: This should only be used in tests.

Types

type LoadSaver

type LoadSaver interface {
	Loader
	Saver
}

LoadSaver is a composite interface of Loader and Saver it is meant to be implemented as thin wrappers around persistent storage like Swarm

type Loader

type Loader interface {
	Load(ctx context.Context, reference []byte) (data []byte, err error)
}

Loader defines a generic interface to retrieve nodes from a persistent storage for read only operations only

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node represents a mantaray Node

func New

func New() *Node

New is the constructor for in-memory Node structure

func NewNodeRef

func NewNodeRef(ref []byte) *Node

NewNodeRef is the exported Node constructor used to represent manifests by reference

func (*Node) Add

func (n *Node) Add(ctx context.Context, path []byte, entry []byte, metadata map[string]string, ls LoadSaver) error

Add adds an entry to the path

func (*Node) Entry added in v0.2.0

func (n *Node) Entry() []byte

Entry returns the value stored on the specific path.

func (*Node) HasPrefix added in v0.3.0

func (n *Node) HasPrefix(ctx context.Context, path []byte, l Loader) (bool, error)

HasPrefix tests whether the node contains prefix path.

func (*Node) IsEdgeType added in v0.3.0

func (n *Node) IsEdgeType() bool

IsEdgeType returns true if the node forks into other nodes.

func (*Node) IsValueType added in v0.3.0

func (n *Node) IsValueType() bool

IsValueType returns true if the node contains entry.

func (*Node) IsWithMetadataType added in v0.3.0

func (n *Node) IsWithMetadataType() bool

IsWithMetadataType returns true if the node contains metadata.

func (*Node) IsWithPathSeparatorType added in v0.3.0

func (n *Node) IsWithPathSeparatorType() bool

IsWithPathSeparatorType returns true if the node path contains separator character.

func (*Node) Lookup

func (n *Node) Lookup(ctx context.Context, path []byte, l Loader) ([]byte, error)

Lookup finds the entry for a path or returns error if not found

func (*Node) LookupNode added in v0.2.0

func (n *Node) LookupNode(ctx context.Context, path []byte, l Loader) (*Node, error)

LookupNode finds the node for a path or returns error if not found

func (*Node) MarshalBinary

func (n *Node) MarshalBinary() (bytes []byte, err error)

MarshalBinary serialises the node

func (*Node) Metadata added in v0.3.0

func (n *Node) Metadata() map[string]string

Metadata returns the metadata stored on the specific path.

func (*Node) Reference added in v0.2.0

func (n *Node) Reference() []byte

Reference returns the address of the mantaray node if saved.

func (*Node) Remove added in v0.2.0

func (n *Node) Remove(ctx context.Context, path []byte, ls LoadSaver) error

Remove removes a path from the node

func (*Node) Save

func (n *Node) Save(ctx context.Context, s Saver) error

Save persists a trie recursively traversing the nodes

func (*Node) SetObfuscationKey added in v0.2.0

func (n *Node) SetObfuscationKey(obfuscationKey []byte)

func (*Node) String added in v0.2.0

func (n *Node) String() string

nolint,errcheck

func (*Node) UnmarshalBinary

func (n *Node) UnmarshalBinary(data []byte) error

UnmarshalBinary deserialises a node

func (*Node) Walk added in v0.2.0

func (n *Node) Walk(ctx context.Context, root []byte, l Loader, walkFn WalkFunc) error

Walk walks the node tree structure rooted at root, calling walkFn for each file or directory in the tree, including root. All errors that arise visiting files and directories are filtered by walkFn.

func (*Node) WalkNode added in v0.2.0

func (n *Node) WalkNode(ctx context.Context, root []byte, l Loader, walkFn WalkNodeFunc) error

WalkNode walks the node tree structure rooted at root, calling walkFn for each node in the tree, including root. All errors that arise visiting nodes are filtered by walkFn.

type Saver

type Saver interface {
	Save(ctx context.Context, data []byte) (reference []byte, err error)
}

Saver defines a generic interface to persist nodes for write operations

type WalkFunc added in v0.2.0

type WalkFunc func(path []byte, isDir bool, err error) error

WalkFunc is the type of the function called for each file or directory visited by Walk.

type WalkNodeFunc added in v0.2.0

type WalkNodeFunc func(path []byte, node *Node, err error) error

WalkNodeFunc is the type of the function called for each node visited by WalkNode.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL