cafs

package module
v0.0.0-...-9b73b1a Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2019 License: MIT Imports: 11 Imported by: 4

README

cafs has moved

cafs is now a subpackage of qfs.

Documentation

Overview

cafs is a "content-addressed-file-systen", which is a generalized interface for working with content-addressed filestores. real-on-the-real, this is a wrapper for IPFS. It looks a lot like the ipfs datastore interface, except the datastore itself determines keys.

This file is pulled from github.com/ipfs/go-ipfs/commands/files It's hoisted here to generalize for all cafs implementations.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotDirectory = errors.New("Couldn't call NextFile(), this isn't a directory")
	ErrNotReader    = errors.New("This file is a directory, can't use Reader functions")
)
View Source
var (
	// ErrNotFound is the canonical error for not finding a value
	ErrNotFound = errors.New("cafs: path not found")
)
View Source
var (
	// SourceAny specifies that content can come from anywhere
	SourceAny = source("any")
)

Functions

func Walk

func Walk(root File, depth int, visit func(f File, depth int) error) (err error)

Walk traverses a file tree calling visit on each node

Types

type AddedFile

type AddedFile struct {
	Path  string
	Name  string
	Bytes int64
	Hash  string
	Size  string
}

AddedFile reports on the results of adding a file to the store TODO - add filepath to this struct

type Adder

type Adder interface {
	// AddFile adds a file or directory of files to the store
	// this function will return immideately, consumers should read
	// from the Added() channel to see the results of file addition.
	AddFile(File) error
	// Added gives a channel to read added files from.
	Added() chan AddedFile
	// In IPFS land close calls adder.Finalize() and adder.PinRoot()
	// (files will only be pinned if the pin flag was set on NewAdder)
	// Close will close the underlying
	Close() error
}

Adder is the interface for adding files to a Filestore. The addition process is parallelized. Implementers must make all required AddFile calls, then call Close to finalize the addition process. Progress can be monitored through the Added() channel

type Fetcher

type Fetcher interface {
	// Fetch gets a file from a source
	Fetch(source Source, key string) (File, error)
}

Fetcher is the interface for getting files from a remote source filestores can opt into the fetcher interface

type File

type File interface {
	// Files implement ReadCloser, but can only be read from or closed if
	// they are not directories
	io.ReadCloser

	// FileName returns a filename associated with this file
	FileName() string

	// FullPath returns the full path used when adding this file
	FullPath() string

	// IsDirectory returns true if the File is a directory (and therefore
	// supports calling `NextFile`) and false if the File is a normal file
	// (and therefor supports calling `Read` and `Close`)
	IsDirectory() bool

	// NextFile returns the next child file available (if the File is a
	// directory). It will return (nil, io.EOF) if no more files are
	// available. If the file is a regular file (not a directory), NextFile
	// will return a non-nil error.
	NextFile() (File, error)
}

File is an interface that provides functionality for handling files/directories as values that can be supplied to commands. For directories, child files are accessed serially by calling `NextFile()`.

type FileInfo

type FileInfo interface {
	AbsPath() string
	Stat() os.FileInfo
}

type Filestore

type Filestore interface {
	// Put places a file or a directory in the store.
	// The most notable difference from a standard file store is the store itself determines
	// the resulting key (google "content addressing" for more info ;)
	// keys returned by put must be prefixed with the PathPrefix,
	// eg. /ipfs/QmZ3KfGaSrb3cnTriJbddCzG7hwQi2j6km7Xe7hVpnsW5S
	Put(file File, pin bool) (key string, err error)

	// Get retrieves the object `value` named by `key`.
	// Get will return ErrNotFound if the key is not mapped to a value.
	Get(key string) (file File, err error)

	// Has returns whether the `key` is mapped to a `value`.
	// In some contexts, it may be much cheaper only to check for existence of
	// a value, rather than retrieving the value itself. (e.g. HTTP HEAD).
	// The default implementation is found in `GetBackedHas`.
	Has(key string) (exists bool, err error)

	// Delete removes the value for given `key`.
	Delete(key string) error

	// NewAdder allocates an Adder instance for adding files to the filestore
	// Adder gives a higher degree of control over the file adding process at the
	// cost of being harder to work with.
	// "pin" is a flag for recursively pinning this object
	// "wrap" sets weather the top level should be wrapped in a directory
	// expect this to change to something like:
	// NewAdder(opt map[string]interface{}) (Adder, error)
	NewAdder(pin, wrap bool) (Adder, error)

	// PathPrefix is a top-level identifier to distinguish between filestores,
	// for exmple: the "ipfs" in /ipfs/QmZ3KfGaSrb3cnTriJbddCzG7hwQi2j6km7Xe7hVpnsW5S
	// a Filestore implementation should always return the same
	PathPrefix() string
}

Filestore is an interface for working with a content-addressed file system. This interface is under active development, expect it to change lots. It's currently form-fitting around IPFS (ipfs.io), with far-off plans to generalize toward compatibility with git (git-scm.com), then maybe other stuff, who knows.

type MapStore

type MapStore struct {
	Pinned  bool
	Network []*MapStore
	Files   map[string]filer
}

MapStore implements Filestore in-memory as a map

An example pulled from tests will create a tree of "cafs" with directories & cafs, with paths properly set: NewMemdir("/a",

NewMemfileBytes("a.txt", []byte("foo")),
NewMemfileBytes("b.txt", []byte("bar")),
NewMemdir("/c",
	NewMemfileBytes("d.txt", []byte("baz")),
	NewMemdir("/e",
		NewMemfileBytes("f.txt", []byte("bat")),
	),
),

) File is an interface that provides functionality for handling cafs/directories as values that can be supplied to commands.

This is pretty close to things that already exist in ipfs and might not be necessary in most situations, but provides a sensible degree of modularity for our purposes: * memdir: github.com/ipfs/go-ipfs/commands/SerialFile * memfs: github.com/ipfs/go-ipfs/commands/ReaderFile

Network simulates IPFS-like behavior, where nodes can connect to each other to retrieve data from other machines

func NewMapstore

func NewMapstore() *MapStore

NewMapstore allocates an instance of a mapstore

func (*MapStore) AddConnection

func (m *MapStore) AddConnection(other *MapStore)

AddConnection sets up pointers from this MapStore to that, and vice versa.

func (MapStore) Delete

func (m MapStore) Delete(key string) error

Delete removes the file from the store with the key

func (*MapStore) Fetch

func (m *MapStore) Fetch(source Source, key string) (File, error)

Fetch returns a File from the store

func (*MapStore) Get

func (m *MapStore) Get(key string) (File, error)

Get returns a File from the store

func (MapStore) Has

func (m MapStore) Has(key string) (exists bool, err error)

Has returns whether the store has a File with the key

func (MapStore) NewAdder

func (m MapStore) NewAdder(pin, wrap bool) (Adder, error)

NewAdder returns an Adder for the store

func (MapStore) PathPrefix

func (m MapStore) PathPrefix() string

PathPrefix returns the prefix on paths in the store

func (*MapStore) Pin

func (m *MapStore) Pin(key string, recursive bool) error

Pin pins a File with the given key

func (MapStore) Print

func (m MapStore) Print() (string, error)

Print converts the store to a string

func (*MapStore) Put

func (m *MapStore) Put(file File, pin bool) (key string, err error)

Put adds a file to the store

func (*MapStore) Unpin

func (m *MapStore) Unpin(key string, recursive bool) error

Unpin unpins a File with the given key

type Memdir

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

Memdir is an in-memory directory Currently it only supports either Memfile & Memdir as links

func NewMemdir

func NewMemdir(path string, links ...File) *Memdir

NewMemdir creates a new Memdir, supplying zero or more links

func (*Memdir) AddChildren

func (d *Memdir) AddChildren(fs ...File)

AddChildren allows any sort of file to be added, but only implementations that implement the PathSetter interface will have properly configured paths.

func (*Memdir) ChildDir

func (d *Memdir) ChildDir(dirname string) *Memdir

func (Memdir) Close

func (Memdir) Close() error

func (Memdir) FileName

func (m Memdir) FileName() string

func (Memdir) FullPath

func (m Memdir) FullPath() string

func (Memdir) IsDirectory

func (Memdir) IsDirectory() bool

func (*Memdir) MakeDirP

func (d *Memdir) MakeDirP(f File) *Memdir

func (*Memdir) NextFile

func (d *Memdir) NextFile() (File, error)

func (Memdir) Read

func (Memdir) Read([]byte) (int, error)

func (*Memdir) SetPath

func (d *Memdir) SetPath(path string)

type Memfile

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

Memfile is an in-memory file

func NewMemfileBytes

func NewMemfileBytes(name string, data []byte) *Memfile

NewMemfileBytes creates a file from a byte slice

func NewMemfileReader

func NewMemfileReader(name string, r io.Reader) *Memfile

NewMemfileBytes creates a file from an io.Reader

func (Memfile) Close

func (m Memfile) Close() error

func (Memfile) FileName

func (m Memfile) FileName() string

func (Memfile) FullPath

func (m Memfile) FullPath() string

func (Memfile) IsDirectory

func (Memfile) IsDirectory() bool

func (Memfile) NextFile

func (Memfile) NextFile() (File, error)

func (Memfile) Read

func (m Memfile) Read(p []byte) (int, error)

func (*Memfile) SetPath

func (m *Memfile) SetPath(path string)

type PathSetter

type PathSetter interface {
	SetPath(path string)
}

PathSetter adds the capacity to modify a path property

type PeekFile

type PeekFile interface {
	SizeFile

	Peek(n int) File
	Length() int
}

type Pinner

type Pinner interface {
	Pin(key string, recursive bool) error
	Unpin(key string, recursive bool) error
}

Pinner interface for content stores that support the concept of pinning (originated by IPFS). Necessarily asynchronous, with no stateful guarantees, currently not testable.

type SizeFile

type SizeFile interface {
	File

	Size() (int64, error)
}

type Source

type Source interface {
	// address should return the base resource identifier in either content
	// or location based addressing schemes
	Address() string
}

Source identifies where a file should come from. examples of different sources could be an HTTP url or P2P node Identifier

type StatFile

type StatFile interface {
	File

	Stat() os.FileInfo
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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