Documentation ¶
Overview ¶
Package io implements convenience objects for working with the ipfs unixfs data format.
Index ¶
- Variables
- func ResolveUnixfsOnce(ctx context.Context, ds ipld.NodeGetter, nd ipld.Node, names []string) (*ipld.Link, []string, error)
- type BufDagReader
- type DagReader
- type Directory
- func (d *Directory) AddChild(ctx context.Context, name string, nd ipld.Node) error
- func (d *Directory) Find(ctx context.Context, name string) (ipld.Node, error)
- func (d *Directory) ForEachLink(ctx context.Context, f func(*ipld.Link) error) error
- func (d *Directory) GetNode() (ipld.Node, error)
- func (d *Directory) GetPrefix() *cid.Prefix
- func (d *Directory) Links(ctx context.Context) ([]*ipld.Link, error)
- func (d *Directory) RemoveChild(ctx context.Context, name string) error
- func (d *Directory) SetPrefix(prefix *cid.Prefix)
- type PBDagReader
- func (dr *PBDagReader) Close() error
- func (dr *PBDagReader) CtxReadFull(ctx context.Context, b []byte) (int, error)
- func (dr *PBDagReader) Offset() int64
- func (dr *PBDagReader) Read(b []byte) (int, error)
- func (dr *PBDagReader) Seek(offset int64, whence int) (int64, error)
- func (dr *PBDagReader) Size() uint64
- func (dr *PBDagReader) WriteTo(w io.Writer) (int64, error)
- type ReadSeekCloser
Constants ¶
This section is empty.
Variables ¶
var ( ErrIsDir = errors.New("this dag node is a directory") ErrCantReadSymlinks = errors.New("cannot currently read symlinks") )
Common errors
var DefaultShardWidth = 256
DefaultShardWidth is the default value used for hamt sharding width.
var ErrNotADir = fmt.Errorf("merkledag node was not a directory or shard")
ErrNotADir implies that the given node was not a unixfs directory
var ShardSplitThreshold = 1000
ShardSplitThreshold specifies how large of an unsharded directory the Directory code will generate. Adding entries over this value will result in the node being restructured into a sharded object.
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 BufDagReader ¶ added in v0.4.14
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) CtxReadFull ¶ added in v0.4.14
CtxReadFull reads the slice onto b.
func (*BufDagReader) Offset ¶ added in v0.4.14
func (rd *BufDagReader) Offset() int64
Offset returns the current offset.
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) Offset() int64 }
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 ¶
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 struct {
// contains filtered or unexported fields
}
Directory allows to work with UnixFS directory nodes, adding and removing children. It allows to work with different directory schemes, like the classic or the HAMT one.
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
NewDirectoryFromNode loads a unixfs directory from the given IPLD node and DAGService.
func (*Directory) Find ¶ added in v0.4.8
Find returns the root node of the file named 'name' within this directory. In the case of HAMT-directories, it will traverse the tree.
func (*Directory) ForEachLink ¶ added in v0.4.8
ForEachLink applies the given function to Links in the directory.
func (*Directory) RemoveChild ¶ added in v0.4.8
RemoveChild removes the child with the given name.
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, pb *ftpb.Data, 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
CtxReadFull reads data from the DAG structured file
func (*PBDagReader) Offset ¶ added in v0.4.14
func (dr *PBDagReader) Offset() int64
Offset returns the current reader offset
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.