Documentation
¶
Overview ¶
Package unixfs implements a data format for files in the IPFS filesystem It is not the only format in ipfs, but it is the one that the filesystem assumes
Index ¶
- Constants
- Variables
- func BytesForMetadata(m *Metadata) ([]byte, error)
- func DataSize(data []byte) (uint64, error)
- func EmptyDirNode() *dag.ProtoNode
- func EmptyFileNode() *dag.ProtoNode
- func FilePBData(data []byte, totalsize uint64) []byte
- func FolderPBData() []byte
- func FromBytes(data []byte) (*pb.Data, error)
- func GetFSType(n *dag.ProtoNode) (pb.Data_DataType, error)
- func GetMetaSubdagRoot(ctx context.Context, n ipld.Node, serv ipld.NodeGetter) (ipld.Node, error)
- func HAMTShardData(data []byte, fanout uint64, hashType uint64) ([]byte, error)
- func ModePermsToUnixPerms(fileMode os.FileMode) uint32
- func ReadUnixFSNodeData(node ipld.Node) (data []byte, err error)
- func SymlinkData(path string) ([]byte, error)
- func UnixPermsToModePerms(unixPerms uint32) os.FileMode
- func UnwrapData(data []byte) ([]byte, error)
- func WrapData(b []byte) []byte
- type DagMetaNodes
- type FSNode
- func (n *FSNode) AddBlockSize(s uint64)
- func (n *FSNode) BlockSize(i int) uint64
- func (n *FSNode) BlockSizes() []uint64
- func (n *FSNode) Data() []byte
- func (n *FSNode) Fanout() uint64
- func (n *FSNode) FileSize() uint64
- func (n *FSNode) GetBytes() ([]byte, error)
- func (n *FSNode) HashType() uint64
- func (n *FSNode) IsDir() bool
- func (n *FSNode) Metadata() []byte
- func (n *FSNode) ModTime() time.Time
- func (n *FSNode) Mode() (m os.FileMode)
- func (n *FSNode) NumChildren() int
- func (n *FSNode) RemoveAllBlockSizes()
- func (n *FSNode) RemoveBlockSize(i int)
- func (n *FSNode) SetData(newData []byte)
- func (n *FSNode) SetModTime(ts time.Time)
- func (n *FSNode) SetMode(m os.FileMode)
- func (n *FSNode) SetModeFromUnixPermissions(unixPerms uint32)
- func (n *FSNode) Type() pb.Data_DataType
- func (n *FSNode) UpdateFilesize(filesizeDiff int64)
- type LinkResult
- type Metadata
Constants ¶
const ( TRaw = pb.Data_Raw TFile = pb.Data_File TDirectory = pb.Data_Directory TMetadata = pb.Data_Metadata TSymlink = pb.Data_Symlink THAMTShard = pb.Data_HAMTShard TTokenMeta = pb.Data_TokenMeta )
Shorthands for protobuffer types
Variables ¶
var ( ErrMalformedFileFormat = errors.New("malformed data in file format") ErrUnrecognizedType = errors.New("unrecognized node type") ErrNotMetadataRoot = errors.New("expected token metadata protobuf dag node") ErrUnexpectedLinks = errors.New("expected more than two links under the given dag node") ErrMetadataAccessDenied = errors.New("Token metadata can not be accessed by default. Use --meta option.") )
Common errors
Functions ¶
func BytesForMetadata ¶
BytesForMetadata wraps the given Metadata as a profobuf message of Data type, setting the DataType to Metadata. The wrapped bytes are itself the result of calling m.Bytes().
func DataSize ¶
DataSize returns the size of the contents in protobuf wrapped slice. For raw data it simply provides the length of it. For Data_Files, it will return the associated filesize. Note that Data_Directories will return an error.
func EmptyDirNode ¶
EmptyDirNode creates an empty folder Protonode.
func EmptyFileNode ¶
EmptyFileNode creates an empty file Protonode.
func FilePBData ¶
FilePBData creates a protobuf File with the given byte slice and returns the marshaled protobuf bytes representing it.
func FolderPBData ¶
func FolderPBData() []byte
FolderPBData returns Bytes that represent a Directory.
func FromBytes ¶
FromBytes unmarshals a byte slice as protobuf Data. Deprecated: Use `FSNodeFromBytes` instead to avoid direct manipulation of `pb.Data`.
func GetMetaSubdagRoot ¶
GetMetaSubdagRoot returns metadata subDag root if the given 'nd' is the dummy root of a DAG with metadata subDag.
func HAMTShardData ¶
HAMTShardData return a `Data_HAMTShard` protobuf message
func ModePermsToUnixPerms ¶ added in v0.8.0
ModePermsToUnixPerms converts the permission bits of an os.FileMode to unix style mode permissions.
func ReadUnixFSNodeData ¶
ReadUnixFSNodeData extracts the UnixFS data from an IPLD node. Raw nodes are (also) processed because they are used as leaf nodes containing (only) UnixFS data.
func SymlinkData ¶
SymlinkData returns a `Data_Symlink` protobuf message for the path you specify.
func UnixPermsToModePerms ¶ added in v0.8.0
UnixPermsToModePerms converts unix style mode permissions to os.FileMode permissions, as it only operates on permission bits it does not set the underlying type (fs.ModeDir, fs.ModeSymlink, etc.) in the returned os.FileMode.
func UnwrapData ¶
UnwrapData unmarshals a protobuf messages and returns the contents.
Types ¶
type DagMetaNodes ¶
func GetChildrenForDagWithMeta ¶
func GetChildrenForDagWithMeta(ctx context.Context, nd ipld.Node, ds ipld.DAGService) (*DagMetaNodes, error)
GetChildrenForDagWithMeta returns a struct containing both the meta root node and the data root node, if the given 'nd' is top of the DAG with token metadata. Return `nil, nil` if 'nd' is no such node and there is no error.
type FSNode ¶
type FSNode struct {
// contains filtered or unexported fields
}
An FSNode represents a filesystem object using the UnixFS specification.
The `NewFSNode` constructor should be used instead of just calling `new(FSNode)` to guarantee that the required (`Type` and `Filesize`) fields in the `format` structure are initialized before marshaling (in `GetBytes()`).
func ExtractFSNode ¶
ExtractFsNode extracts the `unixfs.FSNode` from the `ipld.Node` (assuming this was implemented by a `mdag.ProtoNode`).
func FSNodeFromBytes ¶
FSNodeFromBytes unmarshal a protobuf message onto an FSNode.
func NewFSNode ¶
func NewFSNode(dataType pb.Data_DataType) *FSNode
NewFSNode creates a new FSNode structure with the given `dataType`.
It initializes the (required) `Type` field (that doesn't have a `Set()` accessor so it must be specified at creation), otherwise the `Marshal()` method in `GetBytes()` would fail (`required field "Type" not set`).
It also initializes the `Filesize` pointer field to ensure its value is never nil before marshaling, this is not a required field but it is done to be backwards compatible with previous `go-ipfs` versions hash. (If it wasn't initialized there could be cases where `Filesize` could have been left at nil, when the `FSNode` was created but no data or child nodes were set to adjust it, as is the case in `NewLeaf()`.)
func (*FSNode) AddBlockSize ¶
AddBlockSize adds the size of the next child block of this node
func (*FSNode) BlockSize ¶
BlockSize returns the block size indexed by `i`. TODO: Evaluate if this function should be bounds checking.
func (*FSNode) BlockSizes ¶
BlockSizes gets blocksizes of format
func (*FSNode) ModTime ¶ added in v0.8.0
ModTime returns the stored last modified timestamp if available.
func (*FSNode) NumChildren ¶
NumChildren returns the number of child blocks of this node
func (*FSNode) RemoveAllBlockSizes ¶
func (n *FSNode) RemoveAllBlockSizes()
RemoveAllBlockSizes removes all the child block sizes of this node.
func (*FSNode) RemoveBlockSize ¶
RemoveBlockSize removes the given child block's size.
func (*FSNode) SetData ¶
SetData sets the `Data` field from the internal `format` updating its `Filesize`.
func (*FSNode) SetModTime ¶ added in v0.8.0
SetModTime stores the given last modified timestamp, otherwise nullifies stored timestamp.
func (*FSNode) SetMode ¶ added in v0.8.0
SetMode stores the given mode permissions, or nullifies stored permissions if none were provided and there are no extended bits set.
func (*FSNode) SetModeFromUnixPermissions ¶ added in v0.8.0
SetModeFromUnixPermissions stores the given unix permissions, or nullifies stored permissions if none were provided and there are no extended bits set.
func (*FSNode) Type ¶
func (n *FSNode) Type() pb.Data_DataType
Type retrieves the `Type` field from the internal `format`.
func (*FSNode) UpdateFilesize ¶
UpdateFilesize updates the `Filesize` field from the internal `format` by a signed difference (`filesizeDiff`). TODO: Add assert to check for `Filesize` > 0?
type LinkResult ¶
A LinkResult for any parallel enumeration of links TODO: Should this live in go-ipld-format?
type Metadata ¶
Metadata is used to store additional FSNode information.
func MetadataFromBytes ¶
MetadataFromBytes Unmarshals a protobuf Data message into Metadata. The provided slice should have been encoded with BytesForMetadata().
Directories
¶
Path | Synopsis |
---|---|
Package hamt implements a Hash Array Mapped Trie over ipfs merkledag nodes.
|
Package hamt implements a Hash Array Mapped Trie over ipfs merkledag nodes. |
Package importer implements utilities used to create IPFS DAGs from files and readers.
|
Package importer implements utilities used to create IPFS DAGs from files and readers. |
balanced
Package balanced provides methods to build balanced DAGs, which are generalistic DAGs in which all leaves (nodes representing chunks of data) are at the same distance from the root.
|
Package balanced provides methods to build balanced DAGs, which are generalistic DAGs in which all leaves (nodes representing chunks of data) are at the same distance from the root. |
trickle
Package trickle allows to build trickle DAGs.
|
Package trickle allows to build trickle DAGs. |
Package io implements convenience objects for working with the ipfs unixfs data format.
|
Package io implements convenience objects for working with the ipfs unixfs data format. |
Package mod provides DAG modification utilities to, for example, insert additional nodes in a unixfs DAG or truncate them.
|
Package mod provides DAG modification utilities to, for example, insert additional nodes in a unixfs DAG or truncate them. |
private
|
|