go-unixfs: github.com/ipfs/go-unixfs Index | Files | Directories

package unixfs

import "github.com/ipfs/go-unixfs"

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


Package Files



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

Shorthands for protobuffer types


var (
    ErrMalformedFileFormat = errors.New("malformed data in file format")
    ErrUnrecognizedType    = errors.New("unrecognized node type")

Common errors

func BytesForMetadata Uses

func BytesForMetadata(m *Metadata) ([]byte, error)

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 Uses

func DataSize(data []byte) (uint64, error)

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 Uses

func EmptyDirNode() *dag.ProtoNode

EmptyDirNode creates an empty folder Protonode.

func FilePBData Uses

func FilePBData(data []byte, totalsize uint64) []byte

FilePBData creates a protobuf File with the given byte slice and returns the marshaled protobuf bytes representing it.

func FolderPBData Uses

func FolderPBData() []byte

FolderPBData returns Bytes that represent a Directory.

func FromBytes Uses

func FromBytes(data []byte) (*pb.Data, error)

FromBytes unmarshals a byte slice as protobuf Data. Deprecated: Use `FSNodeFromBytes` instead to avoid direct manipulation of `pb.Data`.

func HAMTShardData Uses

func HAMTShardData(data []byte, fanout uint64, hashType uint64) ([]byte, error)

HAMTShardData return a `Data_HAMTShard` protobuf message

func ReadUnixFSNodeData Uses

func ReadUnixFSNodeData(node ipld.Node) (data []byte, err error)

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 Uses

func SymlinkData(path string) ([]byte, error)

SymlinkData returns a `Data_Symlink` protobuf message for the path you specify.

func UnwrapData Uses

func UnwrapData(data []byte) ([]byte, error)

UnwrapData unmarshals a protobuf messages and returns the contents.

func WrapData Uses

func WrapData(b []byte) []byte

WrapData marshals raw bytes into a `Data_Raw` type protobuf message.

type FSNode Uses

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 Uses

func ExtractFSNode(node ipld.Node) (*FSNode, error)

Extract the `unixfs.FSNode` from the `ipld.Node` (assuming this was implemented by a `mdag.ProtoNode`).

func FSNodeFromBytes Uses

func FSNodeFromBytes(b []byte) (*FSNode, error)

FSNodeFromBytes unmarshal a protobuf message onto an FSNode.

func NewFSNode Uses

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 Uses

func (n *FSNode) AddBlockSize(s uint64)

AddBlockSize adds the size of the next child block of this node

func (*FSNode) BlockSize Uses

func (n *FSNode) BlockSize(i int) uint64

BlockSize returns the block size indexed by `i`. TODO: Evaluate if this function should be bounds checking.

func (*FSNode) BlockSizes Uses

func (n *FSNode) BlockSizes() []uint64

BlockSizes gets blocksizes of format

func (*FSNode) Data Uses

func (n *FSNode) Data() []byte

Data retrieves the `Data` field from the internal `format`.

func (*FSNode) Fanout Uses

func (n *FSNode) Fanout() uint64

Fanout gets fanout of format

func (*FSNode) FileSize Uses

func (n *FSNode) FileSize() uint64

FileSize returns the size of the file.

func (*FSNode) GetBytes Uses

func (n *FSNode) GetBytes() ([]byte, error)

GetBytes marshals this node as a protobuf message.

func (*FSNode) HashType Uses

func (n *FSNode) HashType() uint64

HashType gets hash type of format

func (*FSNode) IsDir Uses

func (n *FSNode) IsDir() bool

IsDir checks whether the node represents a directory

func (*FSNode) NumChildren Uses

func (n *FSNode) NumChildren() int

NumChildren returns the number of child blocks of this node

func (*FSNode) RemoveAllBlockSizes Uses

func (n *FSNode) RemoveAllBlockSizes()

RemoveAllBlockSizes removes all the child block sizes of this node.

func (*FSNode) RemoveBlockSize Uses

func (n *FSNode) RemoveBlockSize(i int)

RemoveBlockSize removes the given child block's size.

func (*FSNode) SetData Uses

func (n *FSNode) SetData(newData []byte)

SetData sets the `Data` field from the internal `format` updating its `Filesize`.

func (*FSNode) Type Uses

func (n *FSNode) Type() pb.Data_DataType

Type retrieves the `Type` field from the internal `format`.

func (*FSNode) UpdateFilesize Uses

func (n *FSNode) UpdateFilesize(filesizeDiff int64)

UpdateFilesize updates the `Filesize` field from the internal `format` by a signed difference (`filesizeDiff`). TODO: Add assert to check for `Filesize` > 0?

type LinkResult Uses

type LinkResult struct {
    Link *ipld.Link
    Err  error

A LinkResult for any parallel enumeration of links TODO: Should this live in go-ipld-format?

type Metadata Uses

type Metadata struct {
    MimeType string
    Size     uint64

Metadata is used to store additional FSNode information.

func MetadataFromBytes Uses

func MetadataFromBytes(b []byte) (*Metadata, error)

MetadataFromBytes Unmarshals a protobuf Data message into Metadata. The provided slice should have been encoded with BytesForMetadata().

func (*Metadata) Bytes Uses

func (m *Metadata) Bytes() ([]byte, error)

Bytes marshals Metadata as a protobuf message of Metadata type.


hamtPackage hamt implements a Hash Array Mapped Trie over ipfs merkledag nodes.
importerPackage importer implements utilities used to create IPFS DAGs from files and readers.
importer/balancedPackage 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.
importer/tricklePackage trickle allows to build trickle DAGs.
ioPackage io implements convenience objects for working with the ipfs unixfs data format.
modPackage mod provides DAG modification utilities to, for example, insert additional nodes in a unixfs DAG or truncate them.

Package unixfs imports 6 packages (graph) and is imported by 73 packages. Updated 2020-05-04. Refresh now. Tools for package owners.