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 BasicDirectory
- func (d *BasicDirectory) AddChild(ctx context.Context, name string, node ipld.Node) error
- func (d *BasicDirectory) EnumLinksAsync(ctx context.Context) <-chan format.LinkResult
- func (d *BasicDirectory) Find(ctx context.Context, name string) (ipld.Node, error)
- func (d *BasicDirectory) ForEachLink(_ context.Context, f func(*ipld.Link) error) error
- func (d *BasicDirectory) GetCidBuilder() cid.Builder
- func (d *BasicDirectory) GetMaxHAMTFanout() int
- func (d *BasicDirectory) GetMaxLinks() int
- func (d *BasicDirectory) GetNode() (ipld.Node, error)
- func (d *BasicDirectory) Links(ctx context.Context) ([]*ipld.Link, error)
- func (d *BasicDirectory) RemoveChild(ctx context.Context, name string) error
- func (d *BasicDirectory) SetCidBuilder(builder cid.Builder)
- func (d *BasicDirectory) SetMaxHAMTFanout(n int)
- func (d *BasicDirectory) SetMaxLinks(n int)
- func (d *BasicDirectory) SetStat(mode os.FileMode, mtime time.Time)
- type DagReader
- type Directory
- type DirectoryOption
- type DynamicDirectory
- func (d *DynamicDirectory) AddChild(ctx context.Context, name string, nd ipld.Node) error
- func (d *DynamicDirectory) RemoveChild(ctx context.Context, name string) error
- func (d *DynamicDirectory) SetMaxHAMTFanout(n int)
- func (d *DynamicDirectory) SetMaxLinks(n int)
- func (d *DynamicDirectory) SetStat(mode os.FileMode, mtime time.Time)
- type HAMTDirectory
- func (d *HAMTDirectory) AddChild(ctx context.Context, name string, nd ipld.Node) error
- func (d *HAMTDirectory) EnumLinksAsync(ctx context.Context) <-chan format.LinkResult
- func (d *HAMTDirectory) Find(ctx context.Context, name string) (ipld.Node, error)
- func (d *HAMTDirectory) ForEachLink(ctx context.Context, f func(*ipld.Link) error) error
- func (d *HAMTDirectory) GetCidBuilder() cid.Builder
- func (d *HAMTDirectory) GetMaxHAMTFanout() int
- func (d *HAMTDirectory) GetMaxLinks() int
- func (d *HAMTDirectory) GetNode() (ipld.Node, error)
- func (d *HAMTDirectory) Links(ctx context.Context) ([]*ipld.Link, error)
- func (d *HAMTDirectory) RemoveChild(ctx context.Context, name string) error
- func (d *HAMTDirectory) SetCidBuilder(builder cid.Builder)
- func (d *HAMTDirectory) SetMaxHAMTFanout(n int)
- func (d *HAMTDirectory) SetMaxLinks(n int)
- func (d *HAMTDirectory) SetStat(mode os.FileMode, mtime time.Time)
- 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") ErrUnkownNodeType = errors.New("unknown node type") ErrSeekNotSupported = errors.New("file does not support seeking") )
Common errors
var DefaultShardWidth = 256
DefaultShardWidth is the default value used for hamt sharding width. Needs to be a power of two (shard entry size) and multiple of 8 (bitfield size).
var ErrNotADir = errors.New("merkledag node was not a directory or shard")
ErrNotADir implies that the given node was not a unixfs directory
var HAMTShardingSize = int(256 * units.KiB)
HAMTShardingSize is a global option that allows switching to a HAMTDirectory when the BasicDirectory grows above the size (in bytes) signalled by this flag. The default size of 0 disables the option. The size is not the *exact* block size of the encoded BasicDirectory but just the estimated size based byte length of links name and CID (BasicDirectory's ProtoNode doesn't use the Data field so this estimate is pretty accurate).
Functions ¶
Types ¶
type BasicDirectory ¶
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 NewBasicDirectory ¶ added in v0.30.0
func NewBasicDirectory(dserv ipld.DAGService, opts ...DirectoryOption) (*BasicDirectory, error)
NewBasicDirectory creates an empty basic directory with the given options.
func NewBasicDirectoryFromNode ¶ added in v0.30.0
func NewBasicDirectoryFromNode(dserv ipld.DAGService, node *mdag.ProtoNode) *BasicDirectory
NewBasicDirectoryFromNode creates a basic directory wrapping the given ProtoNode.
func (*BasicDirectory) AddChild ¶
AddChild implements the `Directory` interface. It adds (or replaces) a link to the given `node` under `name`.
func (*BasicDirectory) EnumLinksAsync ¶
func (d *BasicDirectory) EnumLinksAsync(ctx context.Context) <-chan format.LinkResult
EnumLinksAsync returns a channel which will receive Links in the directory as they are enumerated, where order is not guaranteed
func (*BasicDirectory) ForEachLink ¶
ForEachLink implements the `Directory` interface.
func (*BasicDirectory) GetCidBuilder ¶
func (d *BasicDirectory) GetCidBuilder() cid.Builder
GetCidBuilder implements the `Directory` interface.
func (*BasicDirectory) GetMaxHAMTFanout ¶ added in v0.30.0
func (d *BasicDirectory) GetMaxHAMTFanout() int
GetMaxLinks returns the configured HAMTFanout.
func (*BasicDirectory) GetMaxLinks ¶ added in v0.30.0
func (d *BasicDirectory) GetMaxLinks() int
GetMaxLinks returns the configured MaxLinks.
func (*BasicDirectory) GetNode ¶
func (d *BasicDirectory) GetNode() (ipld.Node, error)
GetNode implements the `Directory` interface.
func (*BasicDirectory) RemoveChild ¶
func (d *BasicDirectory) RemoveChild(ctx context.Context, name string) error
RemoveChild implements the `Directory` interface.
func (*BasicDirectory) SetCidBuilder ¶
func (d *BasicDirectory) SetCidBuilder(builder cid.Builder)
SetCidBuilder implements the `Directory` interface.
func (*BasicDirectory) SetMaxHAMTFanout ¶ added in v0.30.0
func (d *BasicDirectory) SetMaxHAMTFanout(n int)
SetMAXHAMTFanout has no relevance for BasicDirectories.
func (*BasicDirectory) SetMaxLinks ¶ added in v0.30.0
func (d *BasicDirectory) SetMaxLinks(n int)
SetMaxLinks sets the maximum number of links for the Directory, but has no side effects until new children are added (in which case the new limit applies).
type DagReader ¶
type DagReader interface {
ReadSeekCloser
Size() uint64
Mode() os.FileMode
ModTime() time.Time
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 ¶
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 ¶
type Directory interface {
// SetCidBuilder sets the CID Builder of the root node.
SetCidBuilder(cid.Builder)
// 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
// EnumLinksAsync returns a channel which will receive Links in the directory
// as they are enumerated, where order is not guaranteed
EnumLinksAsync(context.Context) <-chan format.LinkResult
// 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.
//
// Returns os.ErrNotExist if the child does not exist.
Find(context.Context, string) (ipld.Node, error)
// RemoveChild removes the child with the given name.
//
// Returns os.ErrNotExist if the child doesn't exist.
RemoveChild(context.Context, string) error
// GetNode returns the root of this directory.
GetNode() (ipld.Node, error)
// GetCidBuilder returns the CID Builder used.
GetCidBuilder() cid.Builder
// GetMaxLinks returns the configured value for MaxLinks.
GetMaxLinks() int
// SetMaxLinks sets the number of links for the directory. Used when converting
// between Basic and HAMT.
SetMaxLinks(n int)
// GetMaxHAMTFanout returns the configured value for MaxHAMTFanout.
GetMaxHAMTFanout() int
// SetMaxHAMTFanout sets the max width of shards when using a HAMT.
// It must be a power of 2 and multiple of 8. Used when converting
// between Basic and HAMT.
SetMaxHAMTFanout(n int)
// SetStat sets the stat information for the directory. Used when
// converting between Basic and HAMT.
SetStat(os.FileMode, time.Time)
}
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, opts ...DirectoryOption) (Directory, error)
NewDirectory returns a Directory implemented by DynamicDirectory containing a BasicDirectory that automatically converts to a from a HAMTDirectory based on HAMTShardingSize, MaxLinks and MaxHAMTFanout (when set).
func NewDirectoryFromNode ¶
NewDirectoryFromNode loads a unixfs directory from the given IPLD node and DAGService.
type DirectoryOption ¶ added in v0.30.0
type DirectoryOption func(d Directory)
A DirectoryOption can be used to initialize directories.
func WithCidBuilder ¶ added in v0.30.0
func WithCidBuilder(cb cid.Builder) DirectoryOption
WithCidBuilder sets the CidBuilder for new Directories.
func WithMaxHAMTFanout ¶ added in v0.30.0
func WithMaxHAMTFanout(n int) DirectoryOption
WithMaxHAMTFanout stablishes the maximum fanout factor (number of links) for a HAMT directory or a Dynamic directory with an underlying HAMT directory:
- On Dynamic directories, it specifies the HAMT fanout when a HAMT used. When unset, DefaultShardWidth applies.
- On pure HAMT directories, it sets the ShardWidth, otherwise DefaultShardWidth is used.
HAMT directories require this value to be a power of 2 and a multiple of 8. If it is not the case, it will not be used and DefaultHAMTWidth will be used instead.
func WithMaxLinks ¶ added in v0.30.0
func WithMaxLinks(n int) DirectoryOption
WithMaxLinks stablishes the max number of links allowed for a Basic directory or a Dynamic directory with an underlying Basic directory:
- On Dynamic directories using a BasicDirectory, it can trigger conversion to HAMT when set and exceeded. The subsequent HAMT nodes will use MaxHAMTFanout as ShardWidth when set, or DefaultShardWidth otherwise. Conversion can be triggered too based on HAMTShardingSize.
- On Dynamic directories using a HAMTDirectory, it can trigger conversion to BasicDirectory when the number of directory entries is below MaxLinks (and HAMTShardingSize allows).
- On pure Basic directories, it causes an error when adding more than MaxLinks children.
type DynamicDirectory ¶
type DynamicDirectory struct {
Directory
}
DynamicDirectory wraps a Directory interface and provides extra logic to switch from BasicDirectory to HAMTDirectory and backwards based on size.
func (*DynamicDirectory) AddChild ¶
AddChild implements the `Directory` interface. We check when adding new entries if we should switch to HAMTDirectory according to global option(s).
func (*DynamicDirectory) RemoveChild ¶
func (d *DynamicDirectory) RemoveChild(ctx context.Context, name string) error
RemoveChild implements the `Directory` interface. Used in the case where we wrap a HAMTDirectory that might need to be downgraded to a BasicDirectory. The upgrade path is in AddChild.
func (*DynamicDirectory) SetMaxHAMTFanout ¶ added in v0.30.0
func (d *DynamicDirectory) SetMaxHAMTFanout(n int)
SetMaxHAMTFanout sets the maximum shard width for HAMT directories. This operation does not produce any side effect and only takes effect on a conversion from Basic to HAMT directory.
func (*DynamicDirectory) SetMaxLinks ¶ added in v0.30.0
func (d *DynamicDirectory) SetMaxLinks(n int)
SetMaxLinks sets the maximum number of links for the underlying Basic directory when used. This operation does not produce any side effects, but the new value may trigger Basic-to-HAMT conversions when adding new children to Basic directories, or HAMT-to-Basic conversion when operating with HAMT directories.
func (*DynamicDirectory) SetStat ¶ added in v0.30.0
func (d *DynamicDirectory) SetStat(mode os.FileMode, mtime time.Time)
SetStat sets stats information. This operation does not produce any side effects. It is taken into account when converting from HAMT to basic directory. Mode or mtime can be set independently by using zero for mtime or mode respectively.
type HAMTDirectory ¶
type HAMTDirectory struct {
// contains filtered or unexported fields
}
HAMTDirectory is the HAMT implementation of `Directory`. (See package `hamt` for more information.)
func NewHAMTDirectory ¶ added in v0.30.0
func NewHAMTDirectory(dserv ipld.DAGService, sizeChange int, opts ...DirectoryOption) (*HAMTDirectory, error)
NewHAMTDirectory creates an empty HAMT directory with the given options.
func NewHAMTDirectoryFromNode ¶ added in v0.30.0
func NewHAMTDirectoryFromNode(dserv ipld.DAGService, node ipld.Node) (*HAMTDirectory, error)
NewHAMTDirectoryFromNode creates a HAMT directory from the given node, which must correspond to an existing HAMT.
func (*HAMTDirectory) EnumLinksAsync ¶
func (d *HAMTDirectory) EnumLinksAsync(ctx context.Context) <-chan format.LinkResult
EnumLinksAsync returns a channel which will receive Links in the directory as they are enumerated, where order is not guaranteed
func (*HAMTDirectory) ForEachLink ¶
ForEachLink implements the `Directory` interface.
func (*HAMTDirectory) GetCidBuilder ¶
func (d *HAMTDirectory) GetCidBuilder() cid.Builder
GetCidBuilder implements the `Directory` interface.
func (*HAMTDirectory) GetMaxHAMTFanout ¶ added in v0.30.0
func (d *HAMTDirectory) GetMaxHAMTFanout() int
GetMaxHAMTFanout returns the maxHAMTFanout value from a HAMTDirectory.
func (*HAMTDirectory) GetMaxLinks ¶ added in v0.30.0
func (d *HAMTDirectory) GetMaxLinks() int
GetMaxLinks returns the maxLinks value from a HAMTDirectory.
func (*HAMTDirectory) GetNode ¶
func (d *HAMTDirectory) GetNode() (ipld.Node, error)
GetNode implements the `Directory` interface.
func (*HAMTDirectory) RemoveChild ¶
func (d *HAMTDirectory) RemoveChild(ctx context.Context, name string) error
RemoveChild implements the `Directory` interface.
func (*HAMTDirectory) SetCidBuilder ¶
func (d *HAMTDirectory) SetCidBuilder(builder cid.Builder)
SetCidBuilder implements the `Directory` interface.
func (*HAMTDirectory) SetMaxHAMTFanout ¶ added in v0.30.0
func (d *HAMTDirectory) SetMaxHAMTFanout(n int)
SetMaxHAMTFanout has no effect and only exists to support Dynamic directories. Max fanout can be set during creation using WithMaxHAMTFanout().
func (*HAMTDirectory) SetMaxLinks ¶ added in v0.30.0
func (d *HAMTDirectory) SetMaxLinks(n int)
SetMaxLinks has no effect and only exists to support Dynamic directories.