io

package
v0.4.17 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package io implements convenience objects for working with the ipfs unixfs data format.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIsDir            = errors.New("this dag node is a directory")
	ErrCantReadSymlinks = errors.New("cannot currently read symlinks")
	ErrUnkownNodeType   = errors.New("unknown node type")
)

Common errors

View Source
var DefaultShardWidth = 256

DefaultShardWidth is the default value used for hamt sharding width.

View Source
var ErrNotADir = fmt.Errorf("merkledag node was not a directory or shard")

ErrNotADir implies that the given node was not a unixfs directory

View Source
var UseHAMTSharding = false

UseHAMTSharding is a global flag that signifies whether or not to use the HAMT sharding scheme for directory creation

Functions

func ResolveUnixfsOnce added in v0.4.5

func ResolveUnixfsOnce(ctx context.Context, ds ipld.NodeGetter, nd ipld.Node, names []string) (*ipld.Link, []string, error)

ResolveUnixfsOnce resolves a single hop of a path through a graph in a unixfs context. This includes handling traversing sharded directories.

Types

type BasicDirectory added in v0.4.17

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

BasicDirectory is the basic implementation of `Directory`. All the entries are stored in a single node.

func (*BasicDirectory) AddChild added in v0.4.17

func (d *BasicDirectory) AddChild(ctx context.Context, name string, node ipld.Node) error

AddChild implements the `Directory` interface. It adds (or replaces) a link to the given `node` under `name`.

func (*BasicDirectory) Find added in v0.4.17

func (d *BasicDirectory) Find(ctx context.Context, name string) (ipld.Node, error)

Find implements the `Directory` interface.

func (d *BasicDirectory) ForEachLink(ctx context.Context, f func(*ipld.Link) error) error

ForEachLink implements the `Directory` interface.

func (*BasicDirectory) GetNode added in v0.4.17

func (d *BasicDirectory) GetNode() (ipld.Node, error)

GetNode implements the `Directory` interface.

func (*BasicDirectory) GetPrefix added in v0.4.17

func (d *BasicDirectory) GetPrefix() *cid.Prefix

GetPrefix implements the `Directory` interface.

func (d *BasicDirectory) Links(ctx context.Context) ([]*ipld.Link, error)

Links implements the `Directory` interface.

func (*BasicDirectory) RemoveChild added in v0.4.17

func (d *BasicDirectory) RemoveChild(ctx context.Context, name string) error

RemoveChild implements the `Directory` interface.

func (*BasicDirectory) SetPrefix added in v0.4.17

func (d *BasicDirectory) SetPrefix(prefix *cid.Prefix)

SetPrefix implements the `Directory` interface.

func (*BasicDirectory) SwitchToSharding added in v0.4.17

func (d *BasicDirectory) SwitchToSharding(ctx context.Context) (Directory, error)

SwitchToSharding returns a HAMT implementation of this directory.

type BufDagReader added in v0.4.14

type BufDagReader struct {
	*bytes.Reader
}

BufDagReader implements a DagReader that reads from a byte slice using a bytes.Reader. It is used for RawNodes.

func NewBufDagReader added in v0.4.5

func NewBufDagReader(b []byte) *BufDagReader

NewBufDagReader returns a DAG reader for the given byte slice. BufDagReader is used to read RawNodes.

func (*BufDagReader) Close added in v0.4.14

func (*BufDagReader) Close() error

Close is a nop.

func (*BufDagReader) CtxReadFull added in v0.4.14

func (rd *BufDagReader) CtxReadFull(ctx context.Context, b []byte) (int, error)

CtxReadFull reads the slice onto b.

func (*BufDagReader) Size added in v0.4.14

func (rd *BufDagReader) Size() uint64

Size returns the size of the buffer.

type DagReader

type DagReader interface {
	ReadSeekCloser
	Size() uint64
	CtxReadFull(context.Context, []byte) (int, error)
}

A DagReader provides read-only read and seek acess to a unixfs file. Different implementations of readers are used for the different types of unixfs/protobuf-encoded nodes.

func NewDagReader

func NewDagReader(ctx context.Context, n ipld.Node, serv ipld.NodeGetter) (DagReader, error)

NewDagReader creates a new reader object that reads the data represented by the given node, using the passed in DAGService for data retrieval

type Directory added in v0.4.8

type Directory interface {

	// SetPrefix sets the CID prefix of the root node.
	SetPrefix(*cid.Prefix)

	// AddChild adds a (name, key) pair to the root node.
	AddChild(context.Context, string, ipld.Node) error

	// ForEachLink applies the given function to Links in the directory.
	ForEachLink(context.Context, func(*ipld.Link) error) error

	// Links returns the all the links in the directory node.
	Links(context.Context) ([]*ipld.Link, error)

	// Find returns the root node of the file named 'name' within this directory.
	// In the case of HAMT-directories, it will traverse the tree.
	Find(context.Context, string) (ipld.Node, error)

	// RemoveChild removes the child with the given name.
	RemoveChild(context.Context, string) error

	// GetNode returns the root of this directory.
	GetNode() (ipld.Node, error)

	// GetPrefix returns the CID Prefix used.
	GetPrefix() *cid.Prefix
}

Directory defines a UnixFS directory. It is used for creating, reading and editing directories. It allows to work with different directory schemes, like the basic or the HAMT implementation.

It just allows to perform explicit edits on a single directory, working with directory trees is out of its scope, they are managed by the MFS layer (which is the main consumer of this interface).

func NewDirectory

func NewDirectory(dserv ipld.DAGService) Directory

NewDirectory returns a Directory. It needs a `DAGService` to add the children.

func NewDirectoryFromNode added in v0.4.8

func NewDirectoryFromNode(dserv ipld.DAGService, node ipld.Node) (Directory, error)

NewDirectoryFromNode loads a unixfs directory from the given IPLD node and DAGService.

type HAMTDirectory added in v0.4.17

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

HAMTDirectory is the HAMT implementation of `Directory`. (See package `hamt` for more information.)

func (*HAMTDirectory) AddChild added in v0.4.17

func (d *HAMTDirectory) AddChild(ctx context.Context, name string, nd ipld.Node) error

AddChild implements the `Directory` interface.

func (*HAMTDirectory) Find added in v0.4.17

func (d *HAMTDirectory) Find(ctx context.Context, name string) (ipld.Node, error)

Find implements the `Directory` interface. It will traverse the tree.

func (d *HAMTDirectory) ForEachLink(ctx context.Context, f func(*ipld.Link) error) error

ForEachLink implements the `Directory` interface.

func (*HAMTDirectory) GetNode added in v0.4.17

func (d *HAMTDirectory) GetNode() (ipld.Node, error)

GetNode implements the `Directory` interface.

func (*HAMTDirectory) GetPrefix added in v0.4.17

func (d *HAMTDirectory) GetPrefix() *cid.Prefix

GetPrefix implements the `Directory` interface.

func (d *HAMTDirectory) Links(ctx context.Context) ([]*ipld.Link, error)

Links implements the `Directory` interface.

func (*HAMTDirectory) RemoveChild added in v0.4.17

func (d *HAMTDirectory) RemoveChild(ctx context.Context, name string) error

RemoveChild implements the `Directory` interface.

func (*HAMTDirectory) SetPrefix added in v0.4.17

func (d *HAMTDirectory) SetPrefix(prefix *cid.Prefix)

SetPrefix implements the `Directory` interface.

type PBDagReader added in v0.4.14

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

PBDagReader provides a way to easily read the data contained in a dag.

func NewPBFileReader added in v0.4.5

func NewPBFileReader(ctx context.Context, n *mdag.ProtoNode, file *ft.FSNode, serv ipld.NodeGetter) *PBDagReader

NewPBFileReader constructs a new PBFileReader.

func (*PBDagReader) Close added in v0.4.14

func (dr *PBDagReader) Close() error

Close closes the reader.

func (*PBDagReader) CtxReadFull added in v0.4.14

func (dr *PBDagReader) CtxReadFull(ctx context.Context, b []byte) (int, error)

CtxReadFull reads data from the DAG structured file

func (*PBDagReader) Read added in v0.4.14

func (dr *PBDagReader) Read(b []byte) (int, error)

Read reads data from the DAG structured file

func (*PBDagReader) Seek added in v0.4.14

func (dr *PBDagReader) Seek(offset int64, whence int) (int64, error)

Seek implements io.Seeker, and will seek to a given offset in the file interface matches standard unix seek TODO: check if we can do relative seeks, to reduce the amount of dagreader recreations that need to happen.

func (*PBDagReader) Size added in v0.4.14

func (dr *PBDagReader) Size() uint64

Size return the total length of the data from the DAG structured file.

func (*PBDagReader) WriteTo added in v0.4.14

func (dr *PBDagReader) WriteTo(w io.Writer) (int64, error)

WriteTo writes to the given writer.

type ReadSeekCloser

type ReadSeekCloser interface {
	io.Reader
	io.Seeker
	io.Closer
	io.WriterTo
}

A ReadSeekCloser implements interfaces to read, copy, seek and close.

Jump to

Keyboard shortcuts

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