filestore

package module
v0.0.0-...-8dbd74d Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package filestore provides a simple interface for managing a store of files, with local and remote store implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error string
const (
	ErrFileNotFound Error = "file was not found"
)

func (Error) Error

func (e Error) Error() string

type File

type File interface {
	Read(b []byte) (int, error)
	Close() error
}

type Filestore

type Filestore interface {
	// Get retrieves a file from the store and returns a read-only File
	// descriptor. The path is relative to the store root. File.Close should be
	// called as soon as the file is no longer in use. ErrFileNotFound is returned
	// if path does not exist.
	Get(ctx context.Context, path string) (File, error)

	// Insert inserts a file into the store. The destination path is relative to
	// the store root. Parent directories are created automatically if needed. If
	// dest already exists, the file is safely overwritten.
	Insert(ctx context.Context, src io.Reader, dest string) error

	// Remove permanently deletes the file from the store. The path is relative to
	// the store root. ErrFileNotFound is returned if path does not exist.
	Remove(ctx context.Context, path string) error

	// Close frees up any resources currently in use.
	Close() error
}

type FilestoreLocal

type FilestoreLocal struct {
	// Dir is the root directory for the filestore.
	Dir string

	// FileMode holds the permission bits given to new files.
	FilePerm fs.FileMode

	// DirMode holds the permission bits given to new directories.
	DirPerm fs.FileMode
}

FilestoreLocal implements Filestore using a local directory.

func NewFilestoreLocal

func NewFilestoreLocal(config ...LocalConfigFunc) (*FilestoreLocal, error)

NewFilestoreLocal creates a new FilestoreLocal initialized with the given root directory.

func (*FilestoreLocal) Close

func (f *FilestoreLocal) Close() error

func (*FilestoreLocal) Get

func (f *FilestoreLocal) Get(_ context.Context, path string) (File, error)

func (*FilestoreLocal) Insert

func (f *FilestoreLocal) Insert(_ context.Context, r io.Reader, dest string) error

func (*FilestoreLocal) Remove

func (f *FilestoreLocal) Remove(_ context.Context, path string) error

type LocalConfigFunc

type LocalConfigFunc func(*FilestoreLocal)

func SetLocalDir

func SetLocalDir(dir string) LocalConfigFunc

func SetLocalDirPerm

func SetLocalDirPerm(perm fs.FileMode) LocalConfigFunc

func SetLocalFilePerm

func SetLocalFilePerm(perm fs.FileMode) LocalConfigFunc

Jump to

Keyboard shortcuts

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