path

package
v0.4.9-rc2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package path implements utilities for resolving paths within ipfs.

Index

Constants

This section is empty.

Variables

View Source
var ErrBadPath = errors.New("invalid 'ipfs ref' path")

ErrBadPath is returned when a given path is incorrectly formatted

View Source
var ErrNoComponents = errors.New(
	"path must contain at least one component")

Paths after a protocol must contain at least one component

Functions

func Join added in v0.4.0

func Join(pths []string) string

func ResolveSingle added in v0.4.5

func ResolveSingle(ctx context.Context, ds dag.DAGService, nd node.Node, names []string) (*node.Link, []string, error)

ResolveSingle simply resolves one hop of a path through a graph with no extra context (does not opaquely resolve through sharded nodes)

func SplitAbsPath

func SplitAbsPath(fpath Path) (*cid.Cid, []string, error)

SplitAbsPath clean up and split fpath. It extracts the first component (which must be a Multihash) and return it separately.

func SplitList added in v0.4.0

func SplitList(pth string) []string

Types

type ErrNoLink struct {
	Name string
	Node *cid.Cid
}

ErrNoLink is returned when a link is not found in a path

func (ErrNoLink) Error

func (e ErrNoLink) Error() string

type Path

type Path string

TODO: debate making this a private struct wrapped in a public interface would allow us to control creation, and cache segments.

func FromCid added in v0.4.5

func FromCid(c *cid.Cid) Path

FromCid safely converts a cid.Cid type to a Path type

func FromSegments added in v0.3.2

func FromSegments(prefix string, seg ...string) (Path, error)

func FromString

func FromString(s string) Path

FromString safely converts a string type to a Path type

func ParseCidToPath added in v0.4.5

func ParseCidToPath(txt string) (Path, error)

func ParsePath added in v0.3.3

func ParsePath(txt string) (Path, error)

func (Path) IsJustAKey added in v0.4.0

func (p Path) IsJustAKey() bool

IsJustAKey returns true if the path is of the form <key> or /ipfs/<key>.

func (*Path) IsValid added in v0.3.3

func (p *Path) IsValid() error

func (Path) PopLastSegment added in v0.4.0

func (p Path) PopLastSegment() (Path, string, error)

PopLastSegment returns a new Path without its final segment, and the final segment, separately. If there is no more to pop (the path is just a key), the original path is returned.

func (Path) Segments

func (p Path) Segments() []string

func (Path) String

func (p Path) String() string

type Resolver

type Resolver struct {
	DAG dag.DAGService

	ResolveOnce func(ctx context.Context, ds dag.DAGService, nd node.Node, names []string) (*node.Link, []string, error)
}

Resolver provides path resolution to IPFS It has a pointer to a DAGService, which is uses to resolve nodes. TODO: now that this is more modular, try to unify this code with the

the resolvers in namesys

func NewBasicResolver added in v0.4.5

func NewBasicResolver(ds dag.DAGService) *Resolver
func (s *Resolver) ResolveLinks(ctx context.Context, ndd node.Node, names []string) ([]node.Node, error)

ResolveLinks iteratively resolves names by walking the link hierarchy. Every node is fetched from the DAGService, resolving the next name. Returns the list of nodes forming the path, starting with ndd. This list is guaranteed never to be empty.

ResolveLinks(nd, []string{"foo", "bar", "baz"}) would retrieve "baz" in ("bar" in ("foo" in nd.Links).Links).Links

func (*Resolver) ResolvePath

func (s *Resolver) ResolvePath(ctx context.Context, fpath Path) (node.Node, error)

ResolvePath fetches the node for given path. It returns the last item returned by ResolvePathComponents.

func (*Resolver) ResolvePathComponents

func (s *Resolver) ResolvePathComponents(ctx context.Context, fpath Path) ([]node.Node, error)

ResolvePathComponents fetches the nodes for each segment of the given path. It uses the first path component as a hash (key) of the first node, then resolves all other components walking the links, with ResolveLinks.

func (*Resolver) ResolveToLastNode added in v0.4.6

func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath Path) (node.Node, []string, error)

Jump to

Keyboard shortcuts

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