cafs

package
v0.0.0-...-a380f54 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2018 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddContent

func AddContent(idx Index, path string, content []byte) (string, bool, error)

Add the path+data to the index. Returns the content sum and true if the content already existed in the index, false otherwise.

func NewCachedFileSystem

func NewCachedFileSystem(src store.FileSystem, cache *FileSystem) (store.FileSystem, <-chan error)

NewCacheFileSystem implements http.FileSystem and caches every request made to src in cache. The returned error channel passes back any errors which occur when files are being concurrently copied into the cache. Both src and cache must be content addressable using the same hashing scheme.

func NewIndex

func NewIndex(fs store.RWFileSystem) (*index, error)

NewIndex creates a new file system index.

Types

type CachedFileSystem

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

CacheFileSystem is an implemetation of http.FileServer which assumes that both the cache and src is content addressable (i.e. file.Stat().Name() is a content hash). More efficient than the standard caching file system since any requested paths which aren't in the index are passed to the src and then their associated content is only downloaded if not already present.

func (*CachedFileSystem) Open

func (c *CachedFileSystem) Open(ctx context.Context, path string) (http.File, error)

Open implements FileSystem. If the required file isn't in the cache then the file is opened from the src, and then concurrently copied into the cache (with errors passed back on the filesystem error channel).

func (*CachedFileSystem) Wait

func (c *CachedFileSystem) Wait() error

Wait blocks until any concurrent caching operations have been completed.

type FileSystem

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

FileSystem is a type which defines a content addressable filesystem.

func New

func New(fs store.RWFileSystem) (*FileSystem, error)

New creates a new content addressable RWFileSystem.

func (*FileSystem) Create

func (s *FileSystem) Create(ctx context.Context, path string) (io.WriteCloser, error)

Create a new file with path. We buffer the contents written to the io.WriteCloser so that the content can be hashed and then written to the underlying RWFileSystem.

func (*FileSystem) Open

func (s *FileSystem) Open(ctx context.Context, path string) (http.File, error)

Open the file with the given path. Uses the internal index to identify which file to open. NB: Stat on the returned file will refer to the internal file.

func (*FileSystem) Wait

func (s *FileSystem) Wait() error

Wait implements RWFileSystem.

type Index

type Index interface {
	// Get returns the real path for the given filename, with true if and only
	// if the path exists in the index.
	Get(path string) (string, bool)

	// Add adds the path to the index, and returns the path to the file
	// and whether the path/content already exists.
	Add(path string, sum string) (bool, error)

	// Exists returns true of the sum is in the index.
	Exists(sum string) bool
}

Index is an interface which contains methods for implementing a content addressable file system.

type InvalidPathError

type InvalidPathError string

InvalidPathError is returned by cachine filesystem when a previous attempt has been made to fetch a file and failed. Prevents further access to the source.

func (*InvalidPathError) Error

func (e *InvalidPathError) Error() string

Error implements error.

Jump to

Keyboard shortcuts

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