fss3

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2023 License: MIT Imports: 15 Imported by: 0

README

FSS3

Build Status Go version Go Reference Go Report Card GitHub release

FSS3 is an S3 filesystem abstraction layer for Golang that implements most of fs, and io interfaces, and os functions. It is based on minio-go which makes it compatible with any S3 compliant service.

Download

go get github.com/aymanbagabas/fss3

Quick Start

package main

import "github.com/aymanbagabas/fss3"

func main() {
	cfg := fss3.Config{
		AccessKeyID:     "AWS_ACCESS_KEY_ID",
		SecretAccessKey: "AWS_SECRET_ACCESS_KEY",
		Endpoint:        "ENDPOINT",
		UseSSL:          true,
		BucketName:      "MY_BUCKET_NAME",
		Region:          "REGION",
		DirFileName:     "_", // special directory file name that stores directory metadata
		Umask:           0, // Don't set umask
	}
	s3, err := fss3.New(cfg)
	if err != nil {
		panic(err)
	}

	err = s3.Mkdir("Newfolder", 0777)
	if err != nil {
		panic(err)
	}

	data := []byte{"hello world"}
	err = s3.WriteFile("Newfolder/myfile.txt", data, 0644)
	if err != nil {
		panic(err)
	}

	err = s3.RemoveAll("Newfolder")
	if err != nil {
		panic(err)
	}
}

License

This library is distributed under the MIT License, see LICENSE for more information.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoFileInfo = errors.New("fileInfo not found")

ErrNoFileInfo is returned when a file info is not found.

Functions

This section is empty.

Types

type Config

type Config struct {
	AccessKeyID     string
	SecretAccessKey string
	Endpoint        string
	Region          string
	UseSSL          bool
	BucketName      string
	Umask           int
	DirFileName     string
}

Config is the configuration for the FSS3 client.

type DirEntry

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

DirEntry implements fs.DirEntry.

func (*DirEntry) Info

func (de *DirEntry) Info() (fs.FileInfo, error)

Info returns the FileInfo structure describing this entry.

func (*DirEntry) IsDir

func (de *DirEntry) IsDir() bool

IsDir reports whether the entry is a directory.

func (*DirEntry) Name

func (de *DirEntry) Name() string

Name returns the base name of the object extracted from its key.

func (*DirEntry) Type

func (de *DirEntry) Type() fs.FileMode

Type returns the type bits for the entry.

type ErrInvalidHeader

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

ErrInvalidHeader is returned when an invalid path is provided.

func (ErrInvalidHeader) Error

func (e ErrInvalidHeader) Error() string

type ErrNotDirectory

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

ErrNotDirectory is returned when a path is not a directory.

func (ErrNotDirectory) Error

func (e ErrNotDirectory) Error() string

type ErrNotEmpty

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

ErrNotEmpty is returned when a directory is not empty.

func (ErrNotEmpty) Error

func (e ErrNotEmpty) Error() string

type FS added in v0.2.0

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

FS implements the fs.FS interface.

func (*FS) Open added in v0.2.0

func (f *FS) Open(name string) (fs.File, error)

Open opens the named object for reading.

func (*FS) ReadDir added in v0.2.0

func (f *FS) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir reads the directory and returns a list of DirEntry.

func (*FS) ReadFile added in v0.2.0

func (f *FS) ReadFile(name string) ([]byte, error)

ReadFile reads the whole object into a byte slice.

func (*FS) Stat added in v0.2.0

func (f *FS) Stat(name string) (fs.FileInfo, error)

Stat returns a FileInfo for the given name.

type FSS3

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

FSS3 represents an opened bucket.

func New added in v0.2.0

func New(cfg Config) (*FSS3, error)

New creates a new FSS3 object

func (*FSS3) Chmod added in v0.2.1

func (fss3 *FSS3) Chmod(name string, mode fs.FileMode) error

Chmod changes the mode of the named file to mode.

func (*FSS3) Create

func (fss3 *FSS3) Create(name string) (*File, error)

Create creates or truncates the named object. The object is created with mode 0666 (before umask).

func (*FSS3) FS added in v0.2.0

func (fss3 *FSS3) FS() fs.FS

FS returns a fs.FS from the FSS3 object

func (*FSS3) Mkdir

func (fss3 *FSS3) Mkdir(name string, mode fs.FileMode) error

Mkdir creates a new directory with the specified name and permission bits.

func (*FSS3) MkdirAll

func (fss3 *FSS3) MkdirAll(name string, mode fs.FileMode) error

MkdirAll creates a directory named path, along with any necessary parents,

func (*FSS3) Open

func (fss3 *FSS3) Open(name string) (*File, error)

Open opens a S3 object using the given name.

func (*FSS3) ReadDir

func (fss3 *FSS3) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir returns a directory listing.

func (*FSS3) ReadFile

func (fss3 *FSS3) ReadFile(name string) ([]byte, error)

ReadFile reads data for an object.

func (*FSS3) Remove

func (fss3 *FSS3) Remove(name string) error

Remove removes the named file or directory. If directory is not empty, it returns an error.

func (*FSS3) RemoveAll

func (fss3 *FSS3) RemoveAll(path string) error

RemoveAll removes path and any children it contains.

func (*FSS3) Stat

func (fss3 *FSS3) Stat(name string) (fs.FileInfo, error)

Stat returns a fs.FileInfo describing the named object.

func (*FSS3) WalkDir added in v0.2.0

func (fss3 *FSS3) WalkDir(root string, fn fs.WalkDirFunc) error

WalkDir walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root.

func (*FSS3) WriteFile

func (fss3 *FSS3) WriteFile(name string, data []byte, perm fs.FileMode) error

WriteFile writes data to an object and creates any necessary parent. It creates the file if it doesn't exist.

func (*FSS3) WriteFrom added in v0.1.1

func (fss3 *FSS3) WriteFrom(name string, r io.Reader, perm fs.FileMode) error

WriteFrom writes the contents of reader to an object.

type File

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

File implements fs.File.

func (*File) Close

func (f *File) Close() error

Close closes the object.

func (*File) Read

func (f *File) Read(b []byte) (int, error)

Read reads up to len(b) bytes from the underlying object.

func (*File) ReadDir

func (f *File) ReadDir(n int) ([]fs.DirEntry, error)

ReadDir returns the entries from a directory.

func (*File) Stat

func (f *File) Stat() (fs.FileInfo, error)

Stat returns the FileInfo structure describing this object.

func (*File) Write

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

Write writes len(p) bytes from p to the object at key.

func (*File) WriteString

func (f *File) WriteString(s string) (int, error)

WriteString writes a string to the object at key.

func (*File) WriteTo

func (f *File) WriteTo(w io.Writer) (int64, error)

WriteTo writes the object data to w until there's no more data to write

type FileInfo

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

FileInfo implements fs.FileInfo.

func (*FileInfo) IsDir

func (fi *FileInfo) IsDir() bool

IsDir is an abbreviation for Mode().IsDir()

func (*FileInfo) ModTime

func (fi *FileInfo) ModTime() time.Time

ModTime returns the last modification time of the object.

func (*FileInfo) Mode

func (fi *FileInfo) Mode() fs.FileMode

Mode returns the file mode bits from the object metadata. Returns 0 on parsing error.

func (*FileInfo) Name

func (fi *FileInfo) Name() string

Name returns the base name of the object extracted from its key.

func (*FileInfo) Size

func (fi *FileInfo) Size() int64

Size returns the file size from the object

func (*FileInfo) Sys

func (fi *FileInfo) Sys() interface{}

Sys is the underlying data source for the object. In this case it is the ObjectInfo.

Jump to

Keyboard shortcuts

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