Documentation
¶
Overview ¶
Package s3fs implements an absfs.Filer for S3-compatible object storage. It provides file operations on S3 buckets using the AWS SDK v2.
Index ¶
- type Config
- type File
- func (f *File) Close() error
- func (f *File) Name() string
- func (f *File) Read(b []byte) (int, error)
- func (f *File) ReadAt(b []byte, off int64) (int, error)
- func (f *File) ReadDir(n int) ([]iosfs.DirEntry, 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(size int64) error
- func (f *File) Write(b []byte) (int, error)
- func (f *File) WriteAt(b []byte, off int64) (int, error)
- func (f *File) WriteString(s string) (int, error)
- type FileSystem
- func (fs *FileSystem) Chmod(name string, mode os.FileMode) error
- func (fs *FileSystem) Chown(name string, uid, gid int) error
- func (fs *FileSystem) Chtimes(name string, atime time.Time, mtime time.Time) error
- func (fs *FileSystem) Mkdir(name string, perm os.FileMode) error
- func (fs *FileSystem) OpenFile(name string, flag int, perm os.FileMode) (absfs.File, error)
- func (fs *FileSystem) ReadDir(name string) ([]iosfs.DirEntry, error)
- func (fs *FileSystem) ReadFile(name string) ([]byte, error)
- func (fs *FileSystem) Remove(name string) error
- func (fs *FileSystem) Rename(oldpath, newpath string) error
- func (fs *FileSystem) Stat(name string) (os.FileInfo, error)
- func (fs *FileSystem) Sub(dir string) (iosfs.FS, error)
- func (fs *FileSystem) Truncate(name string, size int64) error
- type MockS3Client
- func (m *MockS3Client) CopyObject(ctx context.Context, params *s3.CopyObjectInput, optFns ...func(*s3.Options)) (*s3.CopyObjectOutput, error)
- func (m *MockS3Client) DeleteObject(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)
- func (m *MockS3Client) GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)
- func (m *MockS3Client) GetTestObject(key string) ([]byte, bool)
- func (m *MockS3Client) HasObject(key string) bool
- func (m *MockS3Client) HeadObject(ctx context.Context, params *s3.HeadObjectInput, optFns ...func(*s3.Options)) (*s3.HeadObjectOutput, error)
- func (m *MockS3Client) ListObjectsV2(ctx context.Context, params *s3.ListObjectsV2Input, ...) (*s3.ListObjectsV2Output, error)
- func (m *MockS3Client) ObjectCount() int
- func (m *MockS3Client) PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)
- func (m *MockS3Client) PutTestObject(key string, data []byte)
- func (m *MockS3Client) Reset()
- type S3Client
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Bucket string // S3 bucket name
Region string // AWS region
Config *aws.Config // Optional AWS config (if nil, uses default config loading)
}
Config contains the configuration for connecting to S3.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File represents a file in S3.
func (*File) ReadDir ¶
ReadDir reads the contents of the directory and returns a slice of up to n DirEntry values.
func (*File) Readdirnames ¶
Readdirnames reads directory entry names.
type FileSystem ¶
type FileSystem struct {
// contains filtered or unexported fields
}
FileSystem implements absfs.Filer for S3 object storage.
func New ¶
func New(cfg *Config) (*FileSystem, error)
New creates a new S3 filesystem with the given configuration.
func NewWithClient ¶
func NewWithClient(client S3Client, bucket string) *FileSystem
NewWithClient creates a new S3 filesystem with a custom S3 client. This is primarily useful for testing with mock clients.
func NewWithClientAndContext ¶
func NewWithClientAndContext(ctx context.Context, client S3Client, bucket string) *FileSystem
NewWithClientAndContext creates a new S3 filesystem with a custom S3 client and context.
func (*FileSystem) Chmod ¶
func (fs *FileSystem) Chmod(name string, mode os.FileMode) error
Chmod is not supported for S3.
func (*FileSystem) Chown ¶
func (fs *FileSystem) Chown(name string, uid, gid int) error
Chown is not supported for S3.
func (*FileSystem) Mkdir ¶
func (fs *FileSystem) Mkdir(name string, perm os.FileMode) error
Mkdir creates a "directory" in S3 (creates a zero-byte object with trailing slash).
func (*FileSystem) OpenFile ¶
OpenFile opens a file in S3. Note: S3 doesn't support traditional file flags, so this is a simplified implementation.
func (*FileSystem) ReadDir ¶
func (fs *FileSystem) ReadDir(name string) ([]iosfs.DirEntry, error)
ReadDir reads the named directory and returns a list of directory entries sorted by filename.
func (*FileSystem) ReadFile ¶
func (fs *FileSystem) ReadFile(name string) ([]byte, error)
ReadFile reads the named file and returns its contents.
func (*FileSystem) Remove ¶
func (fs *FileSystem) Remove(name string) error
Remove removes a file or directory from S3. For directories, it removes the directory marker (key with trailing slash). Note: S3's DeleteObject succeeds even if the object doesn't exist.
func (*FileSystem) Rename ¶
func (fs *FileSystem) Rename(oldpath, newpath string) error
Rename renames (moves) a file in S3 by copying and deleting.
func (*FileSystem) Stat ¶
func (fs *FileSystem) Stat(name string) (os.FileInfo, error)
Stat returns file info for an S3 object.
type MockS3Client ¶
type MockS3Client struct {
// Error injection for testing failure scenarios
GetObjectErr error
PutObjectErr error
DeleteObjectErr error
CopyObjectErr error
HeadObjectErr error
ListObjectsErr error
// Call tracking for assertions
GetObjectCalls []string
PutObjectCalls []string
DeleteObjectCalls []string
CopyObjectCalls []copyObjectCall
HeadObjectCalls []string
ListObjectsCalls []string
// contains filtered or unexported fields
}
MockS3Client is an in-memory mock implementation of S3Client for testing.
func NewMockS3Client ¶
func NewMockS3Client() *MockS3Client
NewMockS3Client creates a new mock S3 client for testing.
func (*MockS3Client) CopyObject ¶
func (m *MockS3Client) CopyObject(ctx context.Context, params *s3.CopyObjectInput, optFns ...func(*s3.Options)) (*s3.CopyObjectOutput, error)
CopyObject implements S3Client.
func (*MockS3Client) DeleteObject ¶
func (m *MockS3Client) DeleteObject(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)
DeleteObject implements S3Client.
func (*MockS3Client) GetObject ¶
func (m *MockS3Client) GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)
GetObject implements S3Client.
func (*MockS3Client) GetTestObject ¶
func (m *MockS3Client) GetTestObject(key string) ([]byte, bool)
GetTestObject retrieves a test object from the mock store.
func (*MockS3Client) HasObject ¶
func (m *MockS3Client) HasObject(key string) bool
HasObject checks if an object exists in the mock store.
func (*MockS3Client) HeadObject ¶
func (m *MockS3Client) HeadObject(ctx context.Context, params *s3.HeadObjectInput, optFns ...func(*s3.Options)) (*s3.HeadObjectOutput, error)
HeadObject implements S3Client.
func (*MockS3Client) ListObjectsV2 ¶
func (m *MockS3Client) ListObjectsV2(ctx context.Context, params *s3.ListObjectsV2Input, optFns ...func(*s3.Options)) (*s3.ListObjectsV2Output, error)
ListObjectsV2 implements S3Client.
func (*MockS3Client) ObjectCount ¶
func (m *MockS3Client) ObjectCount() int
ObjectCount returns the number of objects in the mock store.
func (*MockS3Client) PutObject ¶
func (m *MockS3Client) PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)
PutObject implements S3Client.
func (*MockS3Client) PutTestObject ¶
func (m *MockS3Client) PutTestObject(key string, data []byte)
PutTestObject adds a test object directly to the mock store.
func (*MockS3Client) Reset ¶
func (m *MockS3Client) Reset()
Reset clears all objects and error injections.
type S3Client ¶
type S3Client interface {
GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)
PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)
DeleteObject(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)
CopyObject(ctx context.Context, params *s3.CopyObjectInput, optFns ...func(*s3.Options)) (*s3.CopyObjectOutput, error)
HeadObject(ctx context.Context, params *s3.HeadObjectInput, optFns ...func(*s3.Options)) (*s3.HeadObjectOutput, error)
ListObjectsV2(ctx context.Context, params *s3.ListObjectsV2Input, optFns ...func(*s3.Options)) (*s3.ListObjectsV2Output, error)
}
S3Client defines the interface for S3 operations used by FileSystem. This interface allows for dependency injection and mock testing.