fsys

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Unlicense Imports: 13 Imported by: 0

README

Fsys - Filesystem Abstraction for Golang

fsys is a package that abstracts the local and the s3 filesystem to try to provide a standard interface for both.

pkg.go.dev documentation

Examples

coming soon

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidStorageType = errors.New("invalid storage type")
	ErrInvalidPath        = errors.New("invalid path")
	ErrFileNotFound       = errors.New("file not found")
	ErrFolderNotFound     = errors.New("folder not found")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Type of storage, can be "local" or "s3"
	Type string

	Path string

	S3Endpoint string
	S3Location string
	S3Secure   bool

	S3AccessID  string
	S3AccessKey string

	S3BucketName string

	// Override default s3 client.
	MinioClient *minio.Client
}

type File

type File struct {
	Name string
	// contains filtered or unexported fields
}

func (*File) Close

func (f *File) Close() error

func (*File) Read

func (f *File) Read(p []byte) (n int, err error)

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

func (*File) Write

func (f *File) Write(p []byte) (n int, err error)

type FileInfo

type FileInfo struct {
	Name    string
	Size    int64
	ModTime time.Time
	IsDir   bool
	// The file permissions, will always be 0777 when using S3.
	Mode os.FileMode
}

type Storage

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

func New

func New(config Config) (*Storage, error)

New creates a new storage interface It takes Config as its parameter. The function returns the Storage interface, and an error, if any.

func (*Storage) Copy

func (s *Storage) Copy(name string, dest string) error

Copy copies a file from one place to another. It takes the file name, and the destination name as its parameter. The function returns an error, if any.

func (*Storage) CopyDir

func (s *Storage) CopyDir(name string, dst string) error

CopyDir copies a directory from one place to another. It takes a folder nae, and the destination folder name as its parameter. The function returns an error, if any.

func (*Storage) Delete

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

Delete deleted a file within the storage interface. It takes a file name as its parameter. The function returns an error, if any.

func (*Storage) DeleteDir

func (s *Storage) DeleteDir(name string) error

DeleteDir deletes all files within a certain directory. It takes a folder name as its parameter. The function returns an error, if any.

func (*Storage) Move

func (s *Storage) Move(name string, dest string) error

Move moves a file from one place to another. It takes a file name, and the destination name as its parameter. The function returns an error, if any.

func (*Storage) Open

func (s *Storage) Open(name string) (*File, error)

Open opens a file within the Storage interface. It takes a file name as its parameter. The function returns a File and an error, if any.

func (*Storage) Read

func (s *Storage) Read(name string) ([]byte, error)

Read opens a file within the Storage interfaces and reads the contents. It takes a file name as its parameter. The function returns a []byte, or an error, if any.

func (*Storage) ReadDir

func (s *Storage) ReadDir(name string) ([]FileInfo, error)

ReadDir reads all files within a certain directory. It takes a folder name as its parameter. The function returns an array of FileInfo, and an error, if any.

func (*Storage) Rename

func (s *Storage) Rename(name, dest string) error

Rename is a wrapper over the Move function.

func (*Storage) Stat

func (s *Storage) Stat(name string) (*FileInfo, error)

Stat grabs the file info from the Storage interface. It takes a file name as its parameter. The function returns FileInfo, and an error, if any.

func (*Storage) Write

func (s *Storage) Write(name string, data []byte, opts WriteOptions) error

Write writes to a file within the Storage interface. It takes a name, a []byte, and WriteOptions as its parameters. The function returns an error, if any.

type WriteOptions

type WriteOptions struct {
	S3Tags map[string]string
}

Jump to

Keyboard shortcuts

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