unixfs

package
v1.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2021 License: MIT Imports: 4 Imported by: 0

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

View Source
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

View Source
var (
	ErrMalformedFileFormat = errors.New("malformed data in file format")
	ErrInvalidDirLocation  = errors.New("found directory node in unexpected place")
	ErrUnrecognizedType    = errors.New("unrecognized node type")
)

Common errors

Functions

func BytesForMetadata

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

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

func EmptyDirNode() *dag.ProtoNode

EmptyDirNode creates an empty folder Protonode.

func FilePBData

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

func FolderPBData() []byte

FolderPBData returns Bytes that represent a Directory.

func FromBytes

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

FromBytes unmarshals a byte slice as protobuf Data.

func SymlinkData

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

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

func UnwrapData

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

UnwrapData unmarshals a protobuf messages and returns the contents.

func WrapData

func WrapData(b []byte) []byte

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

Types

type FSNode

type FSNode struct {
	Data []byte

	// node type of this node
	Type pb.Data_DataType
	// contains filtered or unexported fields
}

An FSNode represents a filesystem object.

func FSNodeFromBytes

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

FSNodeFromBytes unmarshal a protobuf message onto an FSNode.

func (*FSNode) AddBlockSize

func (n *FSNode) AddBlockSize(s uint64)

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

func (*FSNode) FileSize

func (n *FSNode) FileSize() uint64

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) GetBytes

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

GetBytes marshals this node as a protobuf message.

func (*FSNode) NumChildren

func (n *FSNode) NumChildren() int

NumChildren returns the number of child blocks of this node

func (*FSNode) RemoveBlockSize

func (n *FSNode) RemoveBlockSize(i int)

RemoveBlockSize removes the given child block's size.

type Metadata

type Metadata struct {
	MimeType string
	Size     uint64
}

Metadata is used to store additional FSNode information.

func MetadataFromBytes

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

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

Bytes marshals Metadata as a protobuf message of Metadata type.

Directories

Path Synopsis
Package unixfs_pb is a generated protocol buffer package.
Package unixfs_pb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL