base

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LatestVersion is the most recent semantic version of WNFS this
	// implementation reads/writes
	LatestVersion        = SemVer("2.0.0dev")
	DefaultMultihashType = multihash.SHA2_256
)
View Source
const (
	MetadataLinkName = "metadata"
	PublicLinkName   = "public"
	PrivateLinkName  = "private"
	SkeletonLinkName = "skeleton"
	PrettyLinkName   = "p"
	PreviousLinkName = "previous"
	MergeLinkName    = "merge"
	UserlandLinkName = "userland"
)
View Source
const (
	ModeDefault = 644
)

Variables

View Source
var ErrNoCommonHistory = fmt.Errorf("no common history")

ErrNoCommonHistory signifies a merge error where two nodes share no common history

View Source
var ErrNoLink = fmt.Errorf("no link")
View Source
var ErrNotFound = errors.New("not found")
View Source
var Timestamp = time.Now

Functions

func AllKeys

func AllKeys(ctx context.Context, bs blockstore.Blockstore) ([]cid.Cid, error)

func CopyBlocks

func CopyBlocks(ctx context.Context, id cid.Cid, src, dst blockservice.BlockService) error

Copy blocks from src to dst

func DecodeCBOR

func DecodeCBOR(d []byte, v interface{}) error

func EncodeCBOR

func EncodeCBOR(v interface{}) (*bytes.Buffer, error)

func Filename

func Filename(file fs.File) (string, error)

func LessCID

func LessCID(a, b cid.Cid) bool

func NewFileWithInfo

func NewFileWithInfo(fi fs.FileInfo, r io.Reader) (fs.File, error)

NewFileWithInfo creates a new open file with provided file information

func NewMemfileBytes

func NewMemfileBytes(name string, data []byte) fs.File

NewMemfileBytes creates a file from a byte slice

func NewMemfileReader

func NewMemfileReader(name string, r io.Reader) fs.File

NewMemfileReader creates a file from an io.Reader

func SanitizeCBORForJSON

func SanitizeCBORForJSON(v interface{}) (interface{}, error)

Types

type CBORFiler

type CBORFiler interface {
	CBORFile() (fs.File, error)
}

type FSDirEntry

type FSDirEntry struct {
	// contains filtered or unexported fields
}

func NewFSDirEntry

func NewFSDirEntry(name string, isFile bool) FSDirEntry

func (FSDirEntry) Info

func (ds FSDirEntry) Info() (fs.FileInfo, error)

func (FSDirEntry) IsDir

func (de FSDirEntry) IsDir() bool

func (FSDirEntry) Name

func (de FSDirEntry) Name() string

func (FSDirEntry) Type

func (ds FSDirEntry) Type() fs.FileMode

type FSFileInfo

type FSFileInfo struct {
	// contains filtered or unexported fields
}

func NewFSFileInfo

func NewFSFileInfo(name string, size int64, mode fs.FileMode, mtime time.Time, sys interface{}) FSFileInfo

func (FSFileInfo) IsDir

func (fi FSFileInfo) IsDir() bool

func (FSFileInfo) ModTime

func (fi FSFileInfo) ModTime() time.Time

func (FSFileInfo) Mode

func (fi FSFileInfo) Mode() fs.FileMode

func (FSFileInfo) Name

func (fi FSFileInfo) Name() string

func (*FSFileInfo) SetFilename

func (fi *FSFileInfo) SetFilename(name string) error

func (FSFileInfo) Size

func (fi FSFileInfo) Size() int64

func (FSFileInfo) Sys

func (fi FSFileInfo) Sys() interface{}

type File

type File interface {
	Node
}

type FileInfo

type FileInfo interface {
	fs.FileInfo
	Cid() cid.Cid
}

func Stat

func Stat(f fs.File) (FileInfo, error)

type HistoryEntry

type HistoryEntry struct {
	Cid      cid.Cid  `json:"cid"`
	Previous *cid.Cid `json:"previous"`
	Type     NodeType `json:"type"`
	Mtime    int64    `json:"mtime"`
	Size     int64    `json:"size"`

	Key         string `json:"key,omitempty"`
	PrivateName string `json:"privateName,omitempty"`
}

type LDFile

type LDFile interface {
	fs.File
	fs.ReadDirFile
	Data() (interface{}, error)
}

func FileMetadata

func FileMetadata(f fs.File) (LDFile, error)
type Link struct {
	Name string
	Size int64
	Cid  cid.Cid

	IsFile bool
	Mtime  int64
}

func (Link) IPLD

func (l Link) IPLD() *format.Link

func (Link) IsEmpty

func (l Link) IsEmpty() bool
type Links struct {
	// contains filtered or unexported fields
}

func DecodeLinksBlock

func DecodeLinksBlock(blk blocks.Block) (Links, error)
func NewLinks(links ...Link) Links

func (Links) Add

func (ls Links) Add(link Link)

func (Links) EncodeBlock

func (ls Links) EncodeBlock() (blocks.Block, error)

func (Links) Get

func (ls Links) Get(name string) *Link

func (Links) Len

func (ls Links) Len() int

func (Links) Map

func (ls Links) Map() map[string]Link

func (Links) Remove

func (ls Links) Remove(name string) bool

func (Links) Slice

func (ls Links) Slice() []Link

func (Links) SortedSlice

func (ls Links) SortedSlice() []Link

type MergeResult

type MergeResult struct {
	Name     string
	Type     MergeType
	Cid      cid.Cid // finalized (possibly updated) CID
	Userland cid.Cid
	Metadata cid.Cid
	Size     int64
	IsFile   bool

	HamtRoot    *cid.Cid // TODO(b5): refactor this away. unused on public nodes, required for private
	Key         string
	PrivateName string
}

func (MergeResult) CID

func (mr MergeResult) CID() cid.Cid
func (mr MergeResult) ToLink(name string) Link

type MergeType

type MergeType string
const (
	MTInSync      MergeType = "in-sync"
	MTLocalAhead  MergeType = "local-ahead-of-remote"
	MTFastForward MergeType = "fast-forward"
	MTMergeCommit MergeType = "merge-commit"
)

type Metadata

type Metadata interface {
	Metadata() (LDFile, error)
}

type Node

type Node interface {
	fs.File
	fs.FileInfo
	Cid() cid.Cid
	Type() NodeType
	AsHistoryEntry() HistoryEntry
	History(ctx context.Context, limit int) ([]HistoryEntry, error)
	Metadata() (LDFile, error)
}

type NodeType

type NodeType uint8
const (
	NTFile NodeType = iota
	NTLDFile
	NTDir
	NTSymlink    // reserved for future use
	NTUnixFSFile // reserved for future use
	NTUnixFSDir  // reserved for future use
)

func (NodeType) String

func (nt NodeType) String() string

type Path

type Path []string

func MustPath

func MustPath(posix string) Path

func NewPath

func NewPath(posix string) (Path, error)

func (Path) Shift

func (p Path) Shift() (head string, ch Path)

func (Path) String

func (p Path) String() string

type PutResult

type PutResult interface {
	CID() cid.Cid
	ToLink(name string) Link
}

type SemVer

type SemVer string

type Tree

type Tree interface {
	Node
	fs.ReadDirFile
	Get(path Path) (fs.File, error)
	Add(path Path, f fs.File) (PutResult, error)
	Copy(path Path, srcPath string, src fs.FS) (PutResult, error)
	Rm(path Path) (PutResult, error)
	Mkdir(path Path) (PutResult, error)
}

type WritableMetaNode

type WritableMetaNode interface {
	Node
	SetMetadata(v interface{}) error
}

Jump to

Keyboard shortcuts

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