s3

package
v0.1.26 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package s3 provides a thin wrapper around the AWS SDK for Go v2 that mirrors the surface of the internal/azblob package, so that bbb can treat Amazon S3 (and S3-compatible object stores such as MinIO, Cloudflare R2 and Wasabi) as a first-class backend addressed via s3://bucket/key paths.

Index

Constants

View Source
const (
	// Scheme is the path prefix that identifies S3 paths.
	Scheme = "s3://"
)

Variables

This section is empty.

Functions

func CopyServerSide

func CopyServerSide(ctx context.Context, src, dst S3Path, concurrency int, sizeHint int64, onProgress func(copied, total int64)) error

CopyServerSide performs a server-side copy from src to dst within S3. For objects up to 5 GiB the single-request CopyObject API is used; larger objects use a multipart UploadPartCopy. sizeHint, when > 0, avoids a HeadObject call. onProgress, when non-nil, receives (copied, total) updates.

func Delete

func Delete(ctx context.Context, sp S3Path) error

Delete removes a single object.

func DeletePrefix

func DeletePrefix(ctx context.Context, sp S3Path) error

DeletePrefix deletes every object under the path's prefix in batches.

func DownloadFile

func DownloadFile(ctx context.Context, sp S3Path, file *os.File, concurrency int, onProgress func(int64)) (int64, error)

DownloadFile downloads the object into file using parallel ranged GETs via the transfer manager, returning the number of bytes written.

func DownloadStream

func DownloadStream(ctx context.Context, sp S3Path) (io.ReadCloser, error)

DownloadStream opens the object for streaming reads.

func Endpoint

func Endpoint() string

Endpoint returns the configured custom S3 endpoint (BBB_S3_ENDPOINT), an R2 endpoint synthesized from BBB_R2_ACCOUNT_ID, or an empty string for AWS.

func ForcePathStyle

func ForcePathStyle() bool

ForcePathStyle reports whether path-style addressing is forced (BBB_S3_FORCE_PATH_STYLE).

func HeadObject

func HeadObject(ctx context.Context, sp S3Path) (int64, error)

HeadObject returns the size of the object, or an error if it does not exist.

func IsR2 added in v0.1.26

func IsR2() bool

IsR2 reports whether bbb is configured to talk to Cloudflare R2, either via BBB_R2_ACCOUNT_ID or an explicit R2 BBB_S3_ENDPOINT.

func ListRecursiveStream

func ListRecursiveStream(ctx context.Context, sp S3Path, cb func(ObjectMeta) error) error

ListRecursiveStream lists every object under the path (no delimiter), invoking cb with the key relative to the path prefix.

func ListStream

func ListStream(ctx context.Context, sp S3Path, cb func(ObjectMeta) error) error

ListStream lists the immediate children (files and virtual directories) under the path, invoking cb for each. Directories are reported with a trailing '/'.

func MkBucket

func MkBucket(ctx context.Context, bucket string) error

MkBucket creates a bucket, ignoring an already-exists/owned error.

func R2AccountID added in v0.1.26

func R2AccountID() string

R2AccountID returns the Cloudflare account ID in use (from BBB_R2_ACCOUNT_ID or an R2 BBB_S3_ENDPOINT), or an empty string when R2 is not configured.

func SetHTTPClient

func SetHTTPClient(c *http.Client)

SetHTTPClient installs a shared *http.Client used by the S3 SDK client. This allows DNS pinning/caching and debug logging installed on the underlying transport to apply to S3 traffic. Passing nil clears the override. It must be called before the client is first constructed.

func Touch

func Touch(ctx context.Context, sp S3Path) error

Touch creates an empty object at the path (no-op size 0 PutObject).

func UploadFile

func UploadFile(ctx context.Context, sp S3Path, file *os.File, concurrency int, onProgress func(int64)) error

UploadFile uploads a local file to the object using the transfer manager, reporting cumulative bytes via onProgress.

func UploadStream

func UploadStream(ctx context.Context, sp S3Path, reader io.Reader, concurrency int) error

UploadStream uploads the contents of reader to the object using the S3 transfer manager with the given concurrency.

Types

type ObjectMeta

type ObjectMeta struct {
	Name string
	Size int64
}

ObjectMeta is minimal object metadata used for listing.

func List

func List(ctx context.Context, sp S3Path) ([]ObjectMeta, error)

List returns the immediate children under the path.

type S3Path

type S3Path struct {
	Bucket string
	Key    string // may be empty or end with '/' for a virtual directory
}

S3Path represents an s3:// path (bucket/key).

func Parse

func Parse(raw string) (S3Path, error)

Parse parses an s3://bucket[/key] path.

func (S3Path) Child

func (p S3Path) Child(rel string) S3Path

Child returns the path of a relative child of this path.

func (S3Path) IsDirLike

func (p S3Path) IsDirLike() bool

IsDirLike reports whether the path refers to a bucket root or a virtual directory (empty key or key ending in '/').

func (S3Path) String

func (p S3Path) String() string

String renders the path back into its s3://bucket/key form.

func (S3Path) WithDir

func (p S3Path) WithDir() S3Path

WithDir returns a copy of the path whose key is guaranteed to end with '/'.

Jump to

Keyboard shortcuts

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