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
- func CopyServerSide(ctx context.Context, src, dst S3Path, concurrency int, sizeHint int64, ...) error
- func Delete(ctx context.Context, sp S3Path) error
- func DeletePrefix(ctx context.Context, sp S3Path) error
- func DownloadFile(ctx context.Context, sp S3Path, file *os.File, concurrency int, ...) (int64, error)
- func DownloadStream(ctx context.Context, sp S3Path) (io.ReadCloser, error)
- func Endpoint() string
- func ForcePathStyle() bool
- func HeadObject(ctx context.Context, sp S3Path) (int64, error)
- func IsR2() bool
- func ListRecursiveStream(ctx context.Context, sp S3Path, cb func(ObjectMeta) error) error
- func ListStream(ctx context.Context, sp S3Path, cb func(ObjectMeta) error) error
- func MkBucket(ctx context.Context, bucket string) error
- func R2AccountID() string
- func SetHTTPClient(c *http.Client)
- func Touch(ctx context.Context, sp S3Path) error
- func UploadFile(ctx context.Context, sp S3Path, file *os.File, concurrency int, ...) error
- func UploadStream(ctx context.Context, sp S3Path, reader io.Reader, concurrency int) error
- type ObjectMeta
- type S3Path
Constants ¶
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 DeletePrefix ¶
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 ¶
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 ¶
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 ¶
ListRecursiveStream lists every object under the path (no delimiter), invoking cb with the key relative to the path prefix.
func ListStream ¶
ListStream lists the immediate children (files and virtual directories) under the path, invoking cb for each. Directories are reported with a trailing '/'.
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 ¶
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.
Types ¶
type ObjectMeta ¶
ObjectMeta is minimal object metadata used for listing.
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 (S3Path) IsDirLike ¶
IsDirLike reports whether the path refers to a bucket root or a virtual directory (empty key or key ending in '/').