storage

package
v0.0.0-...-43c9aad Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const SizeAll = -1

Variables

View Source
var MemoryStores = map[string]*Memory{}
View Source
var SampleConfig = []string{
	"sftp://username:password@hostname?key=key",
	"s3://accessKey:secret@s3.eu-central-1.amazonaws.com/bucket",
	"file://path",
}

Functions

func CopyFile

func CopyFile(dest Store, destName string, source Store, sourceName string) error

func Dump

func Dump(store Store, dir string, content bool) string

func LoadTestURLs

func LoadTestURLs(filename string) (urls map[string]string)

func ReadFile

func ReadFile(s Store, name string) ([]byte, error)

func ReadJSON

func ReadJSON(s Store, name string, v any, hash hash.Hash) error

func ReadYAML

func ReadYAML(s Store, name string, v interface{}, hash hash.Hash) error

func WriteFile

func WriteFile(s Store, name string, data []byte) error

func WriteJSON

func WriteJSON(s Store, name string, v any, hash hash.Hash) error

func WriteYAML

func WriteYAML(s Store, name string, v interface{}, hash hash.Hash) error

Types

type Description

type Description struct {
	ReadCost  float64 //ReadCost is the cost of reading 1 byte in CHF as per 2023
	WriteCost float64 //WriteCost is the cost of writing 1 byte in CHF as per 2023
}

type Filter

type Filter struct {
	Prefix      string                 //Prefix filters on results starting with prefix
	Suffix      string                 //Suffix filters on results ending with suffix
	AfterName   string                 //After ignore all results before the provided one and the provided one
	After       time.Time              //After ignore all results before the provided one and the provided one
	MaxResults  int64                  //MaxResults limits the number of results returned
	OnlyFiles   bool                   //OnlyFiles returns only files
	OnlyFolders bool                   //OnlyFolders returns only folders
	Function    func(fs.FileInfo) bool //Function filters on a custom function
}

type ListOption

type ListOption uint32
const (
	// IncludeHiddenFiles includes hidden files in a list operation
	IncludeHiddenFiles ListOption = 1
)

type Local

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

func (*Local) Close

func (l *Local) Close() error

func (*Local) Delete

func (l *Local) Delete(name string) error

func (*Local) Describe

func (l *Local) Describe() Description

func (*Local) Read

func (l *Local) Read(name string, rang *Range, dest io.Writer, progress chan int64) error

func (*Local) ReadDir

func (l *Local) ReadDir(dir string, filter Filter) ([]fs.FileInfo, error)

func (*Local) Rename

func (l *Local) Rename(old, new string) error

func (*Local) Stat

func (l *Local) Stat(name string) (os.FileInfo, error)

func (*Local) String

func (l *Local) String() string

func (*Local) Url

func (l *Local) Url() string

func (*Local) Write

func (l *Local) Write(name string, source io.ReadSeeker, progress chan int64) error

type LocalConfig

type LocalConfig struct {
	Base string `json:"base" yaml:"base"`
}

type Memory

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

func (*Memory) Close

func (m *Memory) Close() error

func (*Memory) Delete

func (m *Memory) Delete(name string) error

func (*Memory) Describe

func (m *Memory) Describe() Description

func (*Memory) Read

func (m *Memory) Read(name string, rang *Range, dest io.Writer, progress chan int64) error

func (*Memory) ReadDir

func (m *Memory) ReadDir(dir string, f Filter) ([]fs.FileInfo, error)

func (*Memory) Stat

func (m *Memory) Stat(name string) (os.FileInfo, error)

func (*Memory) String

func (m *Memory) String() string

func (*Memory) Url

func (m *Memory) Url() string

func (*Memory) Write

func (m *Memory) Write(name string, source io.ReadSeeker, progress chan int64) error

type Range

type Range struct {
	From int64
	To   int64
}

type S3

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

func (*S3) Close

func (s *S3) Close() error

func (*S3) Delete

func (s *S3) Delete(name string) error

func (*S3) Describe

func (*S3) Describe() Description

Describe implements Store.

func (*S3) Read

func (s *S3) Read(name string, rang *Range, dest io.Writer, progress chan int64) error

func (*S3) ReadDir

func (s *S3) ReadDir(dir string, f Filter) ([]fs.FileInfo, error)

func (*S3) Rename

func (s *S3) Rename(old, new string) error

func (*S3) Stat

func (s *S3) Stat(name string) (fs.FileInfo, error)

func (*S3) String

func (s *S3) String() string

func (*S3) Url

func (s *S3) Url() string

func (*S3) Write

func (s *S3) Write(name string, source io.ReadSeeker, progress chan int64) error

type SFTP

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

func (*SFTP) Close

func (s *SFTP) Close() error

func (*SFTP) Delete

func (s *SFTP) Delete(name string) error

func (*SFTP) Describe

func (*SFTP) Describe() Description

Describe implements Store.

func (*SFTP) Read

func (s *SFTP) Read(name string, rang *Range, dest io.Writer, progress chan int64) error

func (*SFTP) ReadDir

func (s *SFTP) ReadDir(dir string, f Filter) ([]fs.FileInfo, error)

func (*SFTP) Rename

func (s *SFTP) Rename(old, new string) error

func (*SFTP) Stat

func (s *SFTP) Stat(name string) (os.FileInfo, error)

func (*SFTP) String

func (s *SFTP) String() string

func (*SFTP) Url

func (s *SFTP) Url() string

func (*SFTP) Write

func (s *SFTP) Write(name string, source io.ReadSeeker, progress chan int64) error

type Source

type Source struct {
	Name   string
	Data   []byte
	Reader io.Reader
	Size   int64
}

type Store

type Store interface {
	//ReadDir returns the entries of a folder content
	ReadDir(name string, filter Filter) ([]fs.FileInfo, error)

	// Read reads data from a file into a writer
	Read(name string, rang *Range, dest io.Writer, progress chan int64) error

	// Write writes data to a file name. An existing file is overwritten
	Write(name string, source io.ReadSeeker, progress chan int64) error

	// Stat provides statistics about a file
	Stat(name string) (os.FileInfo, error)

	// Delete deletes a file
	Delete(name string) error

	//Url returns the connection url
	Url() string

	// Close releases resources
	Close() error

	// String returns a human-readable representation of the storer (e.g. sftp://user@host.cc/path)
	String() string

	Describe() Description
}

Store is a low level interface to storage services such as S3 or SFTP

func EncryptNames

func EncryptNames(s Store, key []byte, nonce []byte, propagateClose bool) Store

func Open

func Open(connectionUrl string) (Store, error)

Open creates a new exchanger giving a provided configuration

func OpenLocal

func OpenLocal(connectionUrl string) (Store, error)

func OpenMemory

func OpenMemory(connectionUrl string) (Store, error)

func OpenS3

func OpenS3(connectionUrl string) (Store, error)

func OpenSFTP

func OpenSFTP(connectionUrl string) (Store, error)

OpenSFTP create a new Exchanger. The url is in the format sftp://

func OpenWebDAV

func OpenWebDAV(connectionUrl string) (Store, error)

func Sub

func Sub(s Store, base string, propagateClose bool) Store

type WebDAV

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

func (*WebDAV) Close

func (w *WebDAV) Close() error

func (*WebDAV) Delete

func (w *WebDAV) Delete(name string) error

func (*WebDAV) Describe

func (w *WebDAV) Describe() Description

func (*WebDAV) Read

func (w *WebDAV) Read(name string, rang *Range, dest io.Writer, progress chan int64) error

func (*WebDAV) ReadDir

func (w *WebDAV) ReadDir(dir string, f Filter) ([]fs.FileInfo, error)

func (*WebDAV) Rename

func (w *WebDAV) Rename(old, new string) error

func (*WebDAV) Stat

func (w *WebDAV) Stat(name string) (fs.FileInfo, error)

func (*WebDAV) String

func (w *WebDAV) String() string

func (*WebDAV) Url

func (w *WebDAV) Url() string

func (*WebDAV) Write

func (w *WebDAV) Write(name string, source io.ReadSeeker, progress chan int64) error

Jump to

Keyboard shortcuts

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