s3

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNoSuchKey

func IsNoSuchKey(err error) bool

IsNoSuchKey checks if the error is a missing object error.

Types

type Client

type Client interface {
	Upload(ctx context.Context, key string, data []byte) error
	UploadReader(ctx context.Context, key string, reader io.ReaderAt, size int64) error
	Download(ctx context.Context, key string) ([]byte, error)
	DownloadRange(ctx context.Context, key string, start, end int64) ([]byte, error)
	ObjectExists(ctx context.Context, key string) (bool, error)
	ObjectSize(ctx context.Context, key string) (int64, error)
}

Client interface abstracts S3 operations for easier testing and mocking This matches the previous AWS SDK based implementation.

func NewClient

func NewClient(cfg Config) (client Client, err error)

NewClient creates a new client using ambient credentials.

func NewMockClient

func NewMockClient(server *s3mock.Server, cfg Config) (Client, error)

NewMockClient creates a new S3 client configured to use the mock server.

type Config

type Config struct {
	Bucket  string          // S3 bucket name (required)
	Region  string          // AWS region (required for mock)
	Prefix  string          // S3 key prefix (optional)
	Service string          // S3 service (optional)
	Key     *aws.SigningKey // Optional signing key
}

Config represents the S3-specific configuration.

func NewMockConfig

func NewMockConfig(_ *s3mock.Server, bucket, prefix string) Config

NewMockConfig creates a Config pointing to the mock server.

type ErrS3Operation

type ErrS3Operation struct {
	Operation string
	Err       error
}

ErrS3Operation represents an S3 operation error.

func (ErrS3Operation) Error

func (e ErrS3Operation) Error() string

func (ErrS3Operation) Unwrap

func (e ErrS3Operation) Unwrap() error

type MultiReader

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

MultiReader implements io.ReaderAt for multiple byte slices concatenated together. This avoids expensive memory allocations and copies when combining multiple data sources.

func NewMultiReader

func NewMultiReader(sections ...[]byte) *MultiReader

NewMultiReader creates a new MultiReaderAt from multiple byte slices.

func (*MultiReader) Read

func (m *MultiReader) Read(p []byte) (n int, err error)

Read implements io.Reader interface for compatibility.

func (*MultiReader) ReadAt

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

ReadAt implements io.ReaderAt interface.

func (*MultiReader) Size

func (m *MultiReader) Size() int64

Size returns the total size of all sections combined.

type S3Client

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

S3Client wraps the kelindar/s3 bucket with convenience methods.

func (*S3Client) Download

func (c *S3Client) Download(ctx context.Context, key string) ([]byte, error)

Download downloads an object.

func (*S3Client) DownloadRange

func (c *S3Client) DownloadRange(ctx context.Context, key string, start, end int64) ([]byte, error)

DownloadRange downloads a byte range from S3.

func (*S3Client) ObjectExists

func (c *S3Client) ObjectExists(ctx context.Context, key string) (bool, error)

ObjectExists checks if an object exists.

func (*S3Client) ObjectSize

func (c *S3Client) ObjectSize(ctx context.Context, key string) (int64, error)

ObjectSize returns the size of an object.

func (*S3Client) Upload

func (c *S3Client) Upload(ctx context.Context, key string, data []byte) error

Upload overwrites an S3 object with the given data.

func (*S3Client) UploadReader

func (c *S3Client) UploadReader(ctx context.Context, key string, reader io.ReaderAt, size int64) error

UploadReader uploads data from a ReaderAt to S3.

Jump to

Keyboard shortcuts

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