mantaray

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2021 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var (
	// ErrTooShort signals too short input.
	ErrTooShort = errors.New("serialised input too short")
	// ErrInvalidInput signals invalid input to serialise.
	ErrInvalidInput = errors.New("input invalid")
	// ErrInvalidVersionHash signals unknown version of hash.
	ErrInvalidVersionHash = errors.New("invalid version hash")
)
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

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, entry []byte, metadata map[string]string, ls LoadSaver) error

Add adds an entry to the path

func (*Node) Entry

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

Entry returns the value stored on the specific path.

func (*Node) HasPrefix

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

HasPrefix tests whether the node contains prefix path.

func (*Node) IsEdgeType

func (n *Node) IsEdgeType() bool

IsEdgeType returns true if the node forks into other nodes.

func (*Node) IsValueType

func (n *Node) IsValueType() bool

IsValueType returns true if the node contains entry.

func (*Node) IsWithMetadataType

func (n *Node) IsWithMetadataType() bool

IsWithMetadataType returns true if the node contains metadata.

func (*Node) IsWithPathSeparatorType

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

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

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

Metadata returns the metadata stored on the specific path.

func (*Node) Reference

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

Reference returns the address of the mantaray node if saved.

func (*Node) Remove

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

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

func (*Node) String

func (n *Node) String() string

nolint,errcheck

func (*Node) UnmarshalBinary

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

UnmarshalBinary deserialises a node

func (*Node) Walk

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

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

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

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