path

package
v0.4.15 Latest Latest
Warning

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

Go to latest
Published: May 10, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package path contains utilities to work with ipfs paths.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadPath is returned when a given path is incorrectly formatted
	ErrBadPath = errors.New("invalid 'ipfs ref' path")

	// ErrNoComponents is used when Paths after a protocol
	// do not contain at least one component
	ErrNoComponents = errors.New(
		"path must contain at least one component")
)

Functions

func Join added in v0.4.0

func Join(pths []string) string

Join joins strings slices using /

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

SplitList splits strings usings /

Types

type Path

type Path string

A Path represents an ipfs content path:

  • /<cid>/path/to/file
  • /ipfs/<cid>
  • /ipns/<cid>/path/to/folder
  • etc

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)

FromSegments returns a path given its different segments.

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)

ParseCidToPath takes a CID in string form and returns a valid ipfs Path.

func ParsePath added in v0.3.3

func ParsePath(txt string) (Path, error)

ParsePath returns a well-formed ipfs Path. The returned path will always be prefixed with /ipfs/ or /ipns/. The prefix will be added if not present in the given string. This function will return an error when the given string is not a valid ipfs path.

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

IsValid checks if a path is a valid ipfs Path.

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

Segments returns the different elements of a path (elements are delimited by a /).

func (Path) String

func (p Path) String() string

String converts a path to string.

Directories

Path Synopsis
Package resolver implements utilities for resolving paths within ipfs.
Package resolver implements utilities for resolving paths within ipfs.

Jump to

Keyboard shortcuts

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