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 FilePBData(data []byte, totalsize uint64) []byte
- func FolderPBData() []byte
- func FromBytes(data []byte) (*pb.Data, error)
- func SymlinkData(path string) ([]byte, error)
- func UnwrapData(data []byte) ([]byte, error)
- func WrapData(b []byte) []byte
- type FSNode
- func (n *FSNode) AddBlockSize(s uint64)
- func (n *FSNode) BlockSize(i int) uint64
- func (n *FSNode) Data() []byte
- func (n *FSNode) FileSize() uint64
- func (n *FSNode) GetBytes() ([]byte, error)
- func (n *FSNode) NumChildren() int
- func (n *FSNode) RemoveAllBlockSizes()
- func (n *FSNode) RemoveBlockSize(i int)
- func (n *FSNode) SetData(newData []byte)
- func (n *FSNode) Type() pb.Data_DataType
- func (n *FSNode) UpdateFilesize(filesizeDiff int64)
- 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 )
Shorthands for protobuffer types
Variables ¶
var ( ErrMalformedFileFormat = errors.New("malformed data in file format") ErrUnrecognizedType = errors.New("unrecognized node type") )
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 ¶ added in v0.4.3
EmptyDirNode creates an empty folder 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 SymlinkData ¶ added in v0.3.8
SymlinkData returns a `Data_Symlink` protobuf message for the path you specify.
func UnwrapData ¶
UnwrapData unmarshals a protobuf messages and returns the contents.
Types ¶
type FSNode ¶ added in v0.3.2
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 FSNodeFromBytes ¶ added in v0.3.2
FSNodeFromBytes unmarshal a protobuf message onto an FSNode.
func NewFSNode ¶ added in v0.4.16
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 ¶ added in v0.3.2
AddBlockSize adds the size of the next child block of this node
func (*FSNode) BlockSize ¶ added in v0.4.17
BlockSize returns the block size indexed by `i`. TODO: Evaluate if this function should be bounds checking.
func (*FSNode) FileSize ¶ added in v0.3.2
FileSize returns the total size of this tree. That is, the size of the data in this node plus the size of all its children.
func (*FSNode) NumChildren ¶ added in v0.3.2
NumChildren returns the number of child blocks of this node
func (*FSNode) RemoveAllBlockSizes ¶ added in v0.4.17
func (n *FSNode) RemoveAllBlockSizes()
RemoveAllBlockSizes removes all the child block sizes of this node.
func (*FSNode) RemoveBlockSize ¶ added in v0.3.2
RemoveBlockSize removes the given child block's size.
func (*FSNode) SetData ¶ added in v0.4.16
SetData sets the `Data` field from the internal `format` updating its `Filesize`.
func (*FSNode) Type ¶ added in v0.3.2
func (n *FSNode) Type() pb.Data_DataType
Type retrieves the `Type` field from the internal `format`.
func (*FSNode) UpdateFilesize ¶ added in v0.4.16
UpdateFilesize updates the `Filesize` field from the internal `format` by a signed difference (`filesizeDiff`). TODO: Add assert to check for `Filesize` > 0?
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 archive provides utilities to archive and compress a [Unixfs] DAG.
|
Package archive provides utilities to archive and compress a [Unixfs] DAG. |
tar
Package tar provides functionality to write a unixfs merkledag as a tar archive.
|
Package tar provides functionality to write a unixfs merkledag as a tar archive. |
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 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. |
Package unixfs_pb is a generated protocol buffer package.
|
Package unixfs_pb is a generated protocol buffer package. |