Documentation
¶
Overview ¶
Package s3 implements an S3 filesystem using afero
Package s3 implements an S3 filesystem using afero ¶
Package s3 implements an S3 filesystem using afero
Index ¶
- Variables
- type CompletedPart
- type File
- func (f *File) Close() error
- func (f *File) Name() string
- func (f *File) Read(p []byte) (int, error)
- func (f *File) ReadAt(p []byte, off int64) (n int, err error)
- func (f *File) Readdir(n int) ([]os.FileInfo, error)
- func (f *File) Readdirnames(n int) ([]string, error)
- func (f *File) Seek(offset int64, whence int) (int64, error)
- func (f *File) Stat() (os.FileInfo, error)
- func (f *File) Sync() error
- func (f *File) Truncate(int64) error
- func (f *File) Write(p []byte) (int, error)
- func (f *File) WriteAt(p []byte, off int64) (n int, err error)
- func (f *File) WriteString(s string) (int, error)
- type FileInfo
- type Fs
- func (fs Fs) Chmod(name string, mode os.FileMode, bucket, rootPrefix string) error
- func (Fs) Chown(string, int, int) error
- func (Fs) Chtimes(string, time.Time, time.Time) error
- func (fs *Fs) CompleteMultipartUpload(key, uploadID, bucket, rootPrefix string, parts []CompletedPart) error
- func (fs Fs) Create(name, bucket, rootPrefix string) (afero.File, error)
- func (fs *Fs) GetDiskUsage(bucket, prefix string) (int64, error)
- func (fs *Fs) InitiateMultipartUpload(key, bucket, rootPrefix string) (string, error)
- func (fs *Fs) ListBuckets() ([]string, error)
- func (fs Fs) Mkdir(name string, perm os.FileMode, bucket, rootPrefix string) error
- func (fs Fs) MkdirAll(path string, perm os.FileMode, bucket, rootPrefix string) error
- func (Fs) Name() string
- func (fs *Fs) Open(name, bucket, rootPrefix string) (afero.File, error)
- func (fs *Fs) OpenFile(name string, flag int, _ os.FileMode, bucket, rootPrefix string) (afero.File, error)
- func (fs Fs) Remove(name, bucket, rootPrefix string) error
- func (fs *Fs) RemoveAll(name, bucket, rootPrefix string) error
- func (fs Fs) Rename(oldname, newname, bucket, rootPrefix string) error
- func (fs *Fs) S3API() *s3.Client
- func (fs Fs) Stat(name, bucket, rootPrefix string) (os.FileInfo, error)
- func (fs *Fs) UploadPart(key, uploadID, bucket, rootPrefix string, partNumber int32, data []byte) (string, error)
- type FsWrapper
- func (fw *FsWrapper) Chmod(name string, mode os.FileMode) error
- func (fw *FsWrapper) Chown(name string, uid, gid int) error
- func (fw *FsWrapper) Chtimes(name string, atime time.Time, mtime time.Time) error
- func (fw *FsWrapper) CompleteMultipartUpload(key, uploadID string, parts []CompletedPart) error
- func (fw *FsWrapper) Create(name string) (afero.File, error)
- func (fw *FsWrapper) InitiateMultipartUpload(key string) (string, error)
- func (fw *FsWrapper) ListDirectory(name string, limit int) ([]os.FileInfo, error)
- func (fw *FsWrapper) ListDirectorySimple(name string) ([]os.FileInfo, error)
- func (fw *FsWrapper) Mkdir(name string, perm os.FileMode) error
- func (fw *FsWrapper) MkdirAll(path string, perm os.FileMode) error
- func (fw *FsWrapper) Name() string
- func (fw *FsWrapper) Open(name string) (afero.File, error)
- func (fw *FsWrapper) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error)
- func (fw *FsWrapper) Remove(name string) error
- func (fw *FsWrapper) RemoveAll(path string) error
- func (fw *FsWrapper) Rename(oldname, newname string) error
- func (fw *FsWrapper) Stat(name string) (os.FileInfo, error)
- func (fw *FsWrapper) UploadPart(key, uploadID string, partNumber int32, data []byte) (string, error)
- type UploadedFileProperties
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyOpened = errors.New("already opened")
ErrAlreadyOpened is returned when the file is already opened
var ErrInvalidSeek = errors.New("invalid seek offset")
ErrInvalidSeek is returned when the seek operation is not doable
var ErrNotImplemented = errors.New("not implemented")
ErrNotImplemented is returned when this operation is not (yet) implemented
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 CompletedPart ¶
CompletedPart represents a completed part in multipart upload
type File ¶
type File struct {
// contains filtered or unexported fields
}
File represents a file in S3. nolint: govet
func NewFileWithBucket ¶
NewFileWithBucket initializes a File object with a specific bucket.
func NewFileWithBucketAndPrefix ¶
NewFileWithBucketAndPrefix initializes a File object with a specific bucket and root prefix.
func (*File) Close ¶
Close closes the File, rendering it unusable for I/O. It returns an error, if any.
func (*File) Read ¶
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 ¶
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 ¶
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) Readdirnames ¶
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 ¶
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.
func (*File) Stat ¶
Stat returns the FileInfo structure describing file. If there is an error, it will be of type *PathError.
func (*File) Truncate ¶
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 ¶
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).
type FileInfo ¶
type FileInfo struct {
// contains filtered or unexported fields
}
FileInfo implements os.FileInfo for a file in S3.
func NewFileInfo ¶
NewFileInfo creates file cachedInfo.
func (FileInfo) Mode ¶
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.
type Fs ¶
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 ¶
NewFs creates a new Fs object writing files to a given S3 bucket. The bucket parameter is the S3 bucket name.
func (Fs) Chown ¶
Chown doesn't exist in S3 should probably NOT have been added to afero as it's POSIX-only concept.
func (Fs) Chtimes ¶
Chtimes could be implemented if needed, but that would require to override object properties using metadata, which makes it a non-standard solution
func (*Fs) CompleteMultipartUpload ¶
func (fs *Fs) CompleteMultipartUpload(key, uploadID, bucket, rootPrefix string, parts []CompletedPart) error
CompleteMultipartUpload completes the multipart upload with the given parts
func (*Fs) GetDiskUsage ¶
GetDiskUsage calculates the total size of all objects under the given prefix. This method uses pagination to efficiently handle large directories.
func (*Fs) InitiateMultipartUpload ¶
InitiateMultipartUpload initiates a multipart upload for the given key
func (*Fs) ListBuckets ¶
ListBuckets returns a list of all S3 buckets.
func (*Fs) OpenFile ¶
func (fs *Fs) OpenFile(name string, flag int, _ os.FileMode, bucket, rootPrefix string) (afero.File, error)
OpenFile opens a file.
func (*Fs) RemoveAll ¶
RemoveAll removes a path by listing all objects under the prefix and deleting them in batches. It is much more efficient and reliable on S3 than recursive Readdir + per-file deletes.
func (Fs) Rename ¶
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.
type FsWrapper ¶
FsWrapper wraps the Fs struct to implement afero.Fs interface with fixed bucket and rootPrefix
func NewFsWrapper ¶
NewFsWrapper creates a new FsWrapper object that implements afero.Fs with fixed bucket and rootPrefix.
func (*FsWrapper) CompleteMultipartUpload ¶
func (fw *FsWrapper) CompleteMultipartUpload(key, uploadID string, parts []CompletedPart) error
CompleteMultipartUpload completes the multipart upload with the given parts.
func (*FsWrapper) InitiateMultipartUpload ¶
InitiateMultipartUpload initiates a multipart upload for the given key.
func (*FsWrapper) ListDirectory ¶
ListDirectory is an optimized method to list objects in a directory with limit support using the S3 paginator, which is much more efficient than Readdir(-1) for large directories. Parameters:
- name: directory path
- limit: maximum number of items to return (0 for default, -1 for no limit)
func (*FsWrapper) ListDirectorySimple ¶
ListDirectorySimple provides backward compatibility with the old signature
type UploadedFileProperties ¶
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