s3fs

package module
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: MIT Imports: 18 Imported by: 1

README

s3fs

Package s3fs provides a S3 implementation for Afero

s3fs uses prefixpath to implement buckets

the implementation wraps aws sdk go s3 client.

it is based off of https://github.com/jszwec/s3fs

Installation

go get gfx.cafe/open/s3fs

Requirements

  • Go1.16+

Documentation

Index

Constants

View Source
const READAHEAD = 16 * 1024 * 1024 // 16mb readahead
View Source
const WRITEBUFFER = 8 * 1024 * 1024 // 8mb part size for upload

Variables

View Source
var ErrAlreadyOpened = errors.New("already opened")

ErrAlreadyOpened is returned when the file is already opened

View Source
var ErrInvalidSeek = errors.New("invalid seek offset")

ErrInvalidSeek is returned when the seek operation is not doable

View Source
var ErrNotImplemented = errors.New("not implemented")

ErrNotImplemented is returned when this operation is not (yet) implemented

View Source
var ErrNotSupported = errors.New("s3 doesn't support this operation")

ErrNotSupported is returned when this operations is not supported by S3

Functions

This section is empty.

Types

type File added in v0.5.2

type File struct {
	os.FileInfo // File info cached for later used
	// contains filtered or unexported fields
}

File represents a file in S3. nolint: govet

func NewFile added in v0.5.2

func NewFile(fs *Fs, name string) *File

NewFile initializes an File object.

func (*File) Close added in v0.5.2

func (f *File) Close() error

Close closes the File, rendering it unusable for I/O. It returns an error, if any.

func (*File) Name added in v0.5.2

func (f *File) Name() string

Name returns the filename, i.e. S3 path without the bucket name.

func (*File) RangeReader added in v0.5.2

func (r *File) RangeReader(from, amt int64) (io.ReadCloser, error)

RangeReader produces an io.ReadCloser that reads bytes in the range from [off, off+width)

It is the caller's responsibility to call Close() on the returned io.ReadCloser.

func (*File) Read added in v0.5.2

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

Read reads up to len(b) bytes from the File. It returns the number of bytes read and an error, if any. EOF is signaled by a zero count with err set to io.EOF.

func (*File) ReadAt added in v0.5.2

func (f *File) ReadAt(p []byte, off int64) (n int, err error)

ReadAt reads len(p) bytes from the file starting at byte offset off. It returns the number of bytes read and the error, if any. ReadAt always returns a non-nil error when n < len(b). At end of file, that error is io.EOF.

func (*File) Readdir added in v0.5.2

func (f *File) Readdir(n int) ([]os.FileInfo, error)

Readdir reads the contents of the directory associated with file and returns a slice of up to n FileInfo values, as would be returned by ListObjects, in directory order. Subsequent calls on the same file will yield further FileInfos.

If n > 0, Readdir returns at most n FileInfo structures. In this case, if Readdir returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF.

If n <= 0, Readdir returns all the FileInfo from the directory in a single slice. In this case, if Readdir succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdir returns the FileInfo read until that point and a non-nil error.

func (*File) ReaddirAll added in v0.5.2

func (f *File) ReaddirAll() ([]os.FileInfo, error)

ReaddirAll provides list of file cachedInfo.

func (*File) Readdirnames added in v0.5.2

func (f *File) Readdirnames(n int) ([]string, error)

Readdirnames reads and returns a slice of names from the directory f.

If n > 0, Readdirnames returns at most n names. In this case, if Readdirnames returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF.

If n <= 0, Readdirnames returns all the names from the directory in a single slice. In this case, if Readdirnames succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdirnames returns the names read until that point and a non-nil error.

func (*File) Seek added in v0.5.2

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

Seek sets the offset for the next Read or Write on file to offset, interpreted according to whence: 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end. It returns the new offset and an error, if any. The behavior of Seek on a file opened with O_APPEND is not specified. seeking backwards invalidates the existing read buffer

func (*File) Stat added in v0.5.2

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

Stat returns the FileInfo structure describing file. If there is an error, it will be of type *PathError.

func (*File) Sync added in v0.5.2

func (f *File) Sync() error

Sync is a noop.

func (*File) Truncate added in v0.5.2

func (f *File) Truncate(int64) error

Truncate changes the size of the file. It does not change the I/O offset. If there is an error, it will be of type *PathError.

func (*File) Write added in v0.5.2

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

Write writes len(b) bytes to the File. It returns the number of bytes written and an error, if any. Write returns a non-nil error when n != len(b).

func (*File) WriteAt added in v0.5.2

func (f *File) WriteAt(p []byte, off int64) (n int, err error)

WriteAt writes len(p) bytes to the file starting at byte offset off. It returns the number of bytes written and an error, if any. WriteAt returns a non-nil error when n != len(p).

func (*File) WriteString added in v0.5.2

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

WriteString is like Write, but writes the contents of string s rather than a slice of bytes.

type FileInfo added in v0.0.3

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

FileInfo implements os.FileInfo for a file in S3.

func NewFileInfo added in v0.0.3

func NewFileInfo(name string, directory bool, sizeInBytes int64, modTime time.Time) FileInfo

NewFileInfo creates file cachedInfo.

func (FileInfo) IsDir added in v0.0.3

func (fi FileInfo) IsDir() bool

IsDir provides the abbreviation for Mode().IsDir()

func (FileInfo) ModTime added in v0.0.3

func (fi FileInfo) ModTime() time.Time

ModTime provides the last modification time.

func (FileInfo) Mode added in v0.0.3

func (fi FileInfo) Mode() os.FileMode

Mode provides the file mode bits. For a file in S3 this defaults to 664 for files, 775 for directories. In the future this may return differently depending on the permissions available on the bucket.

func (FileInfo) Name added in v0.0.3

func (fi FileInfo) Name() string

Name provides the base name of the file.

func (FileInfo) Size added in v0.0.3

func (fi FileInfo) Size() int64

Size provides the length in bytes for a file.

func (FileInfo) Sys added in v0.0.3

func (fi FileInfo) Sys() interface{}

Sys provides the underlying data source (can return nil)

type Fs added in v0.5.2

type Fs struct {
	FileProps *UploadedFileProperties // FileProps define the file properties we want to set for all new files
	// contains filtered or unexported fields
}

Fs is an FS object backed by S3.

func NewFs added in v0.5.2

func NewFs(bucket string, session *session.Session) *Fs

NewFs creates a new Fs object writing files to a given S3 bucket.

func (Fs) Chmod added in v0.5.2

func (fs Fs) Chmod(name string, mode os.FileMode) error

Chmod doesn't exists in S3. the original package did this but im not sure if we want to keep it

func (Fs) Chown added in v0.5.2

func (Fs) Chown(string, int, int) error

should do nothing.

func (Fs) Chtimes added in v0.5.2

func (Fs) Chtimes(string, time.Time, time.Time) error

should do nothing

func (Fs) Create added in v0.5.2

func (fs Fs) Create(name string) (afero.File, error)

Create a file.

func (Fs) Mkdir added in v0.5.2

func (fs Fs) Mkdir(name string, perm os.FileMode) error

Mkdir makes a directory in S3.

func (Fs) MkdirAll added in v0.5.2

func (fs Fs) MkdirAll(path string, perm os.FileMode) error

MkdirAll creates a directory and all parent directories if necessary.

func (Fs) Name added in v0.5.2

func (Fs) Name() string

Name returns the type of FS object this is: Fs.

func (*Fs) Open added in v0.5.2

func (fs *Fs) Open(name string) (afero.File, error)

Open a file for reading.

func (*Fs) OpenFile added in v0.5.2

func (fs *Fs) OpenFile(name string, flag int, _ os.FileMode) (afero.File, error)

OpenFile opens a file.

func (Fs) Remove added in v0.5.2

func (fs Fs) Remove(name string) error

Remove a file

func (*Fs) RemoveAll added in v0.5.2

func (fs *Fs) RemoveAll(name string) error

RemoveAll removes a path.

func (Fs) Rename added in v0.5.2

func (fs Fs) Rename(oldname, newname string) error

Rename a file. There is no method to directly rename an S3 object, so the Rename will copy the file to an object with the new name and then delete the original.

func (Fs) Stat added in v0.5.2

func (fs Fs) Stat(name string) (os.FileInfo, error)

Stat returns a FileInfo describing the named file. If there is an error, it will be of type *os.PathError.

type GetOptions added in v0.5.3

type GetOptions struct {
	ReadAhead   int64 // readahead in bytes
	ContentType *string
}

type UploadedFileProperties added in v0.5.2

type UploadedFileProperties struct {
	ACL          *string // ACL defines the right to apply
	CacheControl *string // CacheControl defines the Cache-Control header
	ContentType  *string // ContentType define the Content-Type header
}

UploadedFileProperties defines all the set properties applied to future files

Jump to

Keyboard shortcuts

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