s3kit

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MPL-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

s3kit

Go Reference Go Report Card CI Release

A simple, idiomatic Go SDK for S3-compatible object storage. Works with AWS S3, MinIO, RustFS, and any S3-compatible service.

Features

  • Bucket operations: create, delete, list, check existence, empty
  • Object operations: put, get, delete, copy, move, list
  • Historical object operations by version ID or 1-based version number
  • ListObjects auto-paginates — returns all objects regardless of count
  • DeleteObjects auto-batches — handles any number of keys (1000/request limit handled internally)
  • File upload/download with automatic content-type detection (100+ extensions)
  • DownloadFile is atomic — no partial files left on failure
  • Presigned URLs for GET and PUT
  • Multipart upload/download via aws-sdk-go-v2/feature/s3/transfermanager
  • MinIO Snowball Auto-Extract for .tar, .tgz, and .zip bulk imports
  • Minimal API surface — one struct, zero global state

Common Extension Areas

The current API focuses on the high-frequency object workflows most services need. For a broader S3 component library, these are practical extension areas that fit the same style:

  • Bucket administration: versioning, lifecycle rules, object lock, retention, legal hold
  • Object metadata: tags, user metadata, content disposition, cache control, checksums
  • Security controls: server-side encryption, public access checks, bucket policies, scoped presigned operations
  • Transfer ergonomics: range reads, resumable multipart uploads, multipart copy, progress callbacks
  • Batch workflows: prefix sync, mirror/copy between buckets, manifest-driven delete/copy/move
  • Import/export: archive packing, archive upload, portable archive extraction, Snowball-style bulk migration
  • Observability: structured request logging, retry visibility, transfer metrics, operation timing
  • Compatibility helpers: MinIO/RustFS/AWS endpoint presets, path-style defaults, health checks

Installation

go get github.com/kzzan/s3kit@latest

Requires Go 1.26+.

Quick Start

AWS S3 using the default credential chain

package main

import (
    "context"
    "fmt"
    "log"

    "github.com/kzzan/s3kit"
)

func main() {
    client, err := s3kit.New(s3kit.Config{
        Region:          "us-east-1",
    })
    if err != nil {
        log.Fatal(err)
    }

    ctx := context.Background()

    if err := client.PutObjectBytes(ctx, "my-bucket", "hello.txt", []byte("hello, world"), "text/plain"); err != nil {
        log.Fatal(err)
    }

    data, err := client.GetObjectBytes(ctx, "my-bucket", "hello.txt")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(string(data))
}

s3kit.New uses the AWS SDK v2 default credential chain when AccessKeyID and SecretAccessKey are omitted.

S3-compatible storage with explicit credentials

client, err := s3kit.New(s3kit.Config{
    Endpoint:        "http://localhost:9000",
    AccessKeyID:     "minioadmin",
    SecretAccessKey: "minioadmin",
})

Configuration

Field Description Default
Endpoint S3-compatible endpoint URL. Leave empty for AWS default endpoint resolution. optional
AccessKeyID Access key / username. Leave empty to use the AWS SDK default credential chain. optional
SecretAccessKey Secret key / password paired with AccessKeyID. optional
SessionToken Optional session token for temporary credentials. empty
Region Region name us-east-1

MinIO

client, err := s3kit.New(s3kit.Config{
    Endpoint:        "http://localhost:9000",
    AccessKeyID:     "minioadmin",
    SecretAccessKey: "minioadmin",
    SessionToken:    "",
})
MinIO Snowball Support Guide

In MinIO-centered systems, "Snowball" usually means one of two workflows.

1. Snowball-style archive ingestion

This is a bulk migration pattern for moving many files efficiently. Instead of issuing one S3 request per small file, the producer packs files into an archive, optionally compresses it, uploads the archive as a large object, and then runs an import/extraction workflow on the MinIO side or in a worker process.

Recommended library-level support:

  • Build an archive manifest with source path, target object key, size, checksum, content type, and optional user metadata.
  • Pack small files into tar, tar.gz, or tar.zst archives outside the hot S3 path.
  • Upload the archive with PutObject, UploadFile, or multipart transfer for large files.
  • Verify the uploaded archive size and checksum before extraction/import.
  • Use prefix-scoped destination keys so retries can be idempotent.
  • Record failed entries and resume from the manifest instead of restarting the whole migration.

MinIO can extract .tar, .tgz, and .zip archives on the server when the uploaded object includes this user metadata:

X-Amz-Meta-Snowball-Auto-Extract: true

The MinIO Client equivalent is:

mc cp my-large-files.tar myminio/mybucket/ --attr "X-Amz-Meta-Snowball-Auto-Extract=true"

With s3kit, use UploadFileSnowballAutoExtract for local archive files:

client, err := s3kit.New(s3kit.Config{
    Endpoint:        "http://localhost:9000",
    AccessKeyID:     "minioadmin",
    SecretAccessKey: "minioadmin",
})
if err != nil {
    log.Fatal(err)
}

if err := client.UploadFileSnowballAutoExtract(ctx, "mybucket", "imports/my-large-files.tar", "/data/my-large-files.tar"); err != nil {
    log.Fatal(err)
}

The method sends metadata key snowball-auto-extract=true; the AWS SDK turns that into the wire header x-amz-meta-snowball-auto-extract: true.

For compatibility with AWS S3, RustFS, and MinIO, use TransferArchiveAndExtract in portable mode. Portable mode downloads the archive to a temporary local file, extracts it in the application, and uploads each extracted entry with normal S3 object APIs. The source can be an HTTP(S) or presigned URL, so no source bucket is required:

destination, err := s3kit.New(s3kit.Config{
    Endpoint:        "http://rustfs.example.com:9001",
    AccessKeyID:     "destination-access-key",
    SecretAccessKey: "destination-secret-key",
})
if err != nil {
    log.Fatal(err)
}

result, err := s3kit.TransferArchiveAndExtract(ctx, nil, destination, s3kit.ArchiveTransferOptions{
    SourceURL:             "https://source.example.com/daily/my-large-files.zip?signature=...",
    DestinationBucket:     "imports",
    DestinationArchiveKey: "raw/daily/my-large-files.zip",
    ExtractPrefix:         "expanded/daily/my-large-files/",
    Mode:                  s3kit.ArchiveExtractPortable,
    MaxEntries:            10000,
    MaxUncompressedSize:   20 << 30,
})
if err != nil {
    log.Fatal(err)
}
fmt.Printf("extracted %d objects\n", len(result.Extracted))

Use ArchiveExtractPortable for AWS S3, RustFS, MinIO, and generic S3-compatible targets. Use ArchiveExtractMinIOSnowball only when the destination is MinIO and you want server-side extraction:

_, err := s3kit.TransferArchiveAndExtract(ctx, nil, minio, s3kit.ArchiveTransferOptions{
    SourceURL:             "https://source.example.com/daily/my-large-files.zip?signature=...",
    DestinationBucket:     "imports",
    DestinationArchiveKey: "snowball/daily/my-large-files.zip",
    Mode:                  s3kit.ArchiveExtractMinIOSnowball,
})

For already-open archive streams, use PutObjectSnowballAutoExtract:

file, err := os.Open("/data/my-large-files.zip")
if err != nil {
    log.Fatal(err)
}
defer file.Close()

err = client.PutObjectSnowballAutoExtract(
    ctx,
    "mybucket",
    "imports/my-large-files.zip",
    file,
    "application/zip",
)

2. AWS Snowball device interoperability

AWS Snowball and Snowball Edge expose S3-compatible endpoints for data movement. When a device or gateway is reachable on the network, configure s3kit like any other S3-compatible service. s3kit already enables path-style addressing when Endpoint is set, which is the safest default for appliance-style S3 endpoints.

client, err := s3kit.New(s3kit.Config{
    Endpoint:        "https://snowball-device.local:8080",
    AccessKeyID:     "device-access-key",
    SecretAccessKey: "device-secret-key",
    Region:          "us-east-1",
})

Operational notes:

  • Prefer multipart upload/download for large Snowball transfers.
  • Keep object keys deterministic and prefix-scoped so the same manifest can be replayed.
  • Validate checksums after transfer; device-side ETags are not always enough for business-level verification.
  • Avoid relying on advanced bucket features unless the specific device mode documents support for them.
  • Treat Snowball as an S3-compatible transport target, then use normal AWS import/export procedures outside this package.

RustFS

client, err := s3kit.New(s3kit.Config{
    Endpoint:        "http://localhost:9001",
    AccessKeyID:     "rustfsadmin",
    SecretAccessKey: "rustfsadmin",
})

API Reference

Bucket Operations
err := client.CreateBucket(ctx, "my-bucket")
err := client.DeleteBucket(ctx, "my-bucket")

exists, err := client.BucketExists(ctx, "my-bucket")
err  := client.WaitBucketExists(ctx, "my-bucket", 30*time.Second)

buckets, err := client.ListBuckets(ctx)
err          := client.EmptyBucket(ctx, "my-bucket")
err          := client.EmptyBucketVersions(ctx, "my-bucket")
Object Operations
// Write
err := client.PutObject(ctx, "bucket", "key", reader, "application/octet-stream")
err := client.PutObjectSnowballAutoExtract(ctx, "bucket", "archive.zip", reader, "application/zip")
err := client.PutObjectBytes(ctx, "bucket", "key", data, "text/plain")
err := client.PutObjectBytesSnowballAutoExtract(ctx, "bucket", "archive.zip", data, "application/zip")
versionID, err := client.PutObjectVersion(ctx, "bucket", "key", reader, "application/octet-stream")
versionID, err := client.PutObjectBytesVersion(ctx, "bucket", "key", data, "text/plain")

// Read
body, err := client.GetObject(ctx, "bucket", "key")   // caller must close
data, err := client.GetObjectBytes(ctx, "bucket", "key")
body, err := client.GetObjectVersion(ctx, "bucket", "key", "version-id")
data, err := client.GetObjectVersionBytes(ctx, "bucket", "key", "version-id")
body, err := client.GetObjectVersionByNumber(ctx, "bucket", "key", 2)
data, err := client.GetObjectVersionBytesByNumber(ctx, "bucket", "key", 2)

// Delete
err := client.DeleteObject(ctx, "bucket", "key")
err := client.DeleteObjectVersion(ctx, "bucket", "key", "version-id")
err := client.DeleteObjectVersionByNumber(ctx, "bucket", "key", 2)
err := client.DeleteObjects(ctx, "bucket", []string{"key1", "key2"})  // auto-batches >1000 keys
err := client.DeleteObjectVersions(ctx, "bucket", []s3kit.ObjectVersionIdentifier{
    {Key: "key1", VersionID: "version-id-1"},
    {Key: "key2", VersionID: "version-id-2"},
})
err := client.DeleteObjectVersionsByNumber(ctx, "bucket", []s3kit.ObjectVersionNumberIdentifier{
    {Key: "key1", VersionNumber: 1},
    {Key: "key2", VersionNumber: 2},
})
err := client.DeleteAllObjectVersions(ctx, "bucket", "key")

// Query
exists, err := client.ObjectExists(ctx, "bucket", "key")
exists, err := client.ObjectVersionExists(ctx, "bucket", "key", "version-id")
exists, err := client.ObjectVersionExistsByNumber(ctx, "bucket", "key", 2)
keys,   err := client.ListObjects(ctx, "bucket", "prefix/")  // auto-paginates, returns all objects
versions, err := client.ListObjectVersions(ctx, "bucket", "key")
versionID, err := client.ObjectVersionID(ctx, "bucket", "key", 2)

// Transform
err := client.CopyObject(ctx, "src-bucket", "src-key", "dst-bucket", "dst-key")
versionID, err := client.CopyObjectVersion(ctx, "src-bucket", "src-key", "version-id", "dst-bucket", "dst-key")
versionID, err := client.CopyObjectVersionByNumber(ctx, "src-bucket", "src-key", 2, "dst-bucket", "dst-key")
err := client.MoveObject(ctx, "bucket", "old-key", "new-key")
versionID, err := client.MoveObjectVersion(ctx, "bucket", "old-key", "version-id", "new-key")
versionID, err := client.MoveObjectVersionByNumber(ctx, "bucket", "old-key", 2, "new-key")
File Transfer
// Content-type is detected automatically from the file extension
err := client.UploadFile(ctx, "bucket", "key", "/path/to/file.jpg")
versionID, err := client.UploadFileVersion(ctx, "bucket", "key", "/path/to/file.jpg")

// MinIO Snowball Auto-Extract: uploads the archive with
// x-amz-meta-snowball-auto-extract: true
err := client.UploadFileSnowballAutoExtract(ctx, "bucket", "imports/data.tar", "/path/to/data.tar")

// Atomic: creates parent directories, writes to a temp file first, renames on success
err := client.DownloadFile(ctx, "bucket", "key", "/path/to/dest.jpg")
err := client.DownloadFileVersion(ctx, "bucket", "key", "/path/to/dest.jpg", "version-id")
err := client.DownloadFileVersionByNumber(ctx, "bucket", "key", "/path/to/dest.jpg", 2)
MinIO Snowball Auto-Extract Transfer
err := s3kit.TransferSnowballAutoExtract(ctx, source, destination, s3kit.SnowballAutoExtractTransferOptions{
    SourceBucket:      "exports",
    SourceKey:         "archive.zip",
    DestinationBucket: "imports",
    DestinationKey:    "snowball/archive.zip",
})

err = s3kit.TransferSnowballAutoExtract(ctx, nil, destination, s3kit.SnowballAutoExtractTransferOptions{
    SourceURL:         "https://source.example.com/archive.zip?signature=...",
    DestinationBucket: "imports",
    DestinationKey:    "snowball/archive.zip",
})

The source client reads the archive with GetObject; the destination client uploads it with multipart transfer and x-amz-meta-snowball-auto-extract: true. Use SourceURL for presigned or HTTP(S) sources when no source bucket is available. Use this mode only when the destination is MinIO.

Portable Archive Transfer and Extraction
result, err := s3kit.TransferArchiveAndExtract(ctx, nil, destination, s3kit.ArchiveTransferOptions{
    SourceURL:             "https://source.example.com/archive.tgz?signature=...",
    DestinationBucket:     "imports",
    DestinationArchiveKey: "raw/archive.tgz",
    ExtractPrefix:         "expanded/archive/",
    Mode:                  s3kit.ArchiveExtractPortable,
})

Portable mode supports .zip, .tar, .tgz, and .tar.gz. It works with AWS S3, MinIO, RustFS, and generic S3-compatible destinations because it extracts in the application and writes normal objects. Set SourceURL for presigned or HTTP(S) sources when no source bucket is available; otherwise pass a source client with SourceBucket and SourceKey.

Presigned URLs
url, err := client.PresignGetObject(ctx, "bucket", "key", time.Hour)
url, err := client.PresignGetObjectVersion(ctx, "bucket", "key", "version-id", time.Hour)
url, err := client.PresignGetObjectVersionByNumber(ctx, "bucket", "key", 2, time.Hour)
url, err := client.PresignPutObject(ctx, "bucket", "key", 15*time.Minute)

Development

go test ./...
go vet ./...
go mod tidy

CI also runs golangci-lint, govulncheck, and a go mod tidy drift check on every pull request.

Versioning Policy

  • The module target is Go 1.26 and the codebase prefers current Go syntax and standard library APIs.
  • The current public line is v0.x. In Go module semantics, v0 means the API is still stabilizing and compatibility promises are intentionally weaker.
  • New public releases are published by pushing a semantic version tag such as v0.0.2, v0.1.0, or v1.0.0. That tag is what Go tooling and pkg.go.dev index.
  • For the current v0 line:
    • v0.0.z should be used for fixes and low-risk adjustments.
    • v0.y.0 may include API reshaping while the package is still being validated.
    • even in v0, avoid unnecessary breakage because early adopters still pin these versions in production.
  • Once the exported API and behavior are intentionally stable, cut v1.0.0. From that point on, v1 patch and minor releases should remain backward compatible.
  • Breaking changes after v1.0.0 must ship in a new major module path such as github.com/kzzan/s3kit/v2, not by rewriting v1.
  • Dependency upgrades should default to go get -u=patch ./... plus a full test run.
  • Pre-v1 modules require extra review because SemVer compatibility guarantees are weaker before v1.0.0.

Release Process

git tag v0.0.2
git push origin v0.0.2

The release workflow validates the tag, creates a GitHub Release, and warms the Go module proxy so the new version is picked up by pkg.go.dev without changing older published versions.

License

Mozilla Public License 2.0

Documentation

Overview

Package s3kit provides a small, idiomatic client for S3-compatible object storage built on top of AWS SDK for Go v2.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidArchiveEntryName = errors.New("s3kit: invalid archive entry name")
	ErrArchiveEntryLimit       = errors.New("s3kit: archive entry limit exceeded")
	ErrArchiveSizeLimit        = errors.New("s3kit: archive uncompressed size limit exceeded")
	ErrUnsupportedArchive      = errors.New("s3kit: unsupported archive format")
)
View Source
var (
	// ErrInvalidVersionNumber 表示传入的对象版本号不是正整数。
	ErrInvalidVersionNumber = errors.New("s3kit: version number must be greater than zero")
	// ErrObjectVersionNotFound 表示请求的对象历史版本不存在。
	ErrObjectVersionNotFound = errors.New("s3kit: object version not found")
)

Functions

func TransferSnowballAutoExtract added in v0.0.4

func TransferSnowballAutoExtract(
	ctx context.Context,
	source *Client,
	destination *Client,
	opts SnowballAutoExtractTransferOptions,
) error

TransferSnowballAutoExtract streams a remote archive from source to destination and asks the destination MinIO server to extract it.

The source can be any S3-compatible endpoint that supports GetObject. The destination must be MinIO with Snowball Auto-Extract enabled, otherwise the archive is stored as a normal object with user metadata.

Types

type ArchiveExtractMode added in v0.0.4

type ArchiveExtractMode string
const (
	// ArchiveExtractPortable extracts the archive in the application and uploads
	// each file as a normal object. It works with AWS S3, MinIO, RustFS, and
	// generic S3-compatible targets.
	ArchiveExtractPortable ArchiveExtractMode = "portable"
	// ArchiveExtractMinIOSnowball uploads the archive with MinIO's
	// x-amz-meta-snowball-auto-extract metadata. It is faster for MinIO bulk
	// imports but is not portable to AWS S3 or RustFS.
	ArchiveExtractMinIOSnowball ArchiveExtractMode = "minio-snowball"
)

type ArchiveExtractedObject added in v0.0.4

type ArchiveExtractedObject struct {
	Name        string
	Key         string
	Size        int64
	ContentType string
}

type ArchiveFormat added in v0.0.4

type ArchiveFormat string
const (
	ArchiveFormatAuto  ArchiveFormat = ""
	ArchiveFormatZip   ArchiveFormat = "zip"
	ArchiveFormatTar   ArchiveFormat = "tar"
	ArchiveFormatTarGz ArchiveFormat = "tar.gz"
)

type ArchiveTransferOptions added in v0.0.4

type ArchiveTransferOptions struct {
	// SourceBucket and SourceKey identify the source object when SourceURL is
	// empty.
	SourceBucket string
	SourceKey    string
	// SourceURL is an optional HTTP(S) or presigned S3 URL. When set, SourceBucket
	// is not required and source may be nil.
	SourceURL string
	// DestinationBucket receives the extracted objects. DestinationArchiveKey is
	// optional in portable mode and required in MinIO Snowball mode.
	DestinationBucket     string
	DestinationArchiveKey string
	// ExtractPrefix is prepended to extracted object keys in portable mode.
	ExtractPrefix string
	// Mode defaults to ArchiveExtractPortable for cross-provider compatibility.
	Mode ArchiveExtractMode
	// Format defaults to auto-detection from SourceKey, SourceURL, or
	// DestinationArchiveKey.
	Format ArchiveFormat
	// ContentType optionally overrides the uploaded archive content type in
	// MinIO Snowball mode.
	ContentType string
	// TempDir optionally selects where portable mode stores the temporary archive.
	TempDir string
	// MaxEntries optionally limits extracted file entries in portable mode. Zero
	// means unlimited.
	MaxEntries int
	// MaxUncompressedSize optionally limits total extracted bytes in portable
	// mode. Zero means unlimited.
	MaxUncompressedSize int64
}

ArchiveTransferOptions configures TransferArchiveAndExtract.

type ArchiveTransferResult added in v0.0.4

type ArchiveTransferResult struct {
	Mode          ArchiveExtractMode
	ArchiveKey    string
	Extracted     []ArchiveExtractedObject
	ServerExtract bool
}

func TransferArchiveAndExtract added in v0.0.4

func TransferArchiveAndExtract(
	ctx context.Context,
	source *Client,
	destination *Client,
	opts ArchiveTransferOptions,
) (*ArchiveTransferResult, error)

TransferArchiveAndExtract moves an archive from S3 or HTTP(S) into a destination bucket and extracts it.

Portable mode works with AWS S3, MinIO, RustFS, and generic S3-compatible targets by extracting in the application and uploading each file. MinIO Snowball mode streams the archive to MinIO with server-side auto-extract metadata for higher bulk-import throughput.

type Client

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

Client wraps the S3 and transfer manager clients used by the package.

func New

func New(cfg Config) (*Client, error)

New builds a Client with a background context.

func NewContext added in v0.0.2

func NewContext(ctx context.Context, cfg Config) (*Client, error)

NewContext builds a Client using the provided context while loading AWS configuration.

func (*Client) BucketExists

func (c *Client) BucketExists(ctx context.Context, name string) (bool, error)

BucketExists reports whether a bucket exists.

func (*Client) CopyObject

func (c *Client) CopyObject(ctx context.Context, srcBucket, srcKey, dstBucket, dstKey string) error

CopyObject copies an object to a new bucket/key pair.

func (*Client) CopyObjectVersion added in v0.0.3

func (c *Client) CopyObjectVersion(
	ctx context.Context,
	srcBucket string,
	srcKey string,
	srcVersionID string,
	dstBucket string,
	dstKey string,
) (string, error)

CopyObjectVersion 按 VersionID 复制源对象历史版本,并在目标桶启用版本控制时返回新 VersionID。

func (*Client) CopyObjectVersionByNumber added in v0.0.3

func (c *Client) CopyObjectVersionByNumber(
	ctx context.Context,
	srcBucket string,
	srcKey string,
	versionNumber int,
	dstBucket string,
	dstKey string,
) (string, error)

CopyObjectVersionByNumber 按从 1 开始的版本号复制源对象历史版本。

func (*Client) CreateBucket

func (c *Client) CreateBucket(ctx context.Context, name string) error

CreateBucket creates a bucket.

func (*Client) DeleteAllObjectVersions added in v0.0.3

func (c *Client) DeleteAllObjectVersions(ctx context.Context, bucket, key string) error

DeleteAllObjectVersions 永久删除单个对象 key 的所有历史版本和删除标记。

func (*Client) DeleteBucket

func (c *Client) DeleteBucket(ctx context.Context, name string) error

DeleteBucket deletes a bucket.

func (*Client) DeleteObject

func (c *Client) DeleteObject(ctx context.Context, bucket, key string) error

DeleteObject deletes a single object.

func (*Client) DeleteObjectVersion added in v0.0.3

func (c *Client) DeleteObjectVersion(ctx context.Context, bucket, key, versionID string) error

DeleteObjectVersion 按 VersionID 永久删除指定对象历史版本。

func (*Client) DeleteObjectVersionByNumber added in v0.0.3

func (c *Client) DeleteObjectVersionByNumber(
	ctx context.Context,
	bucket string,
	key string,
	versionNumber int,
) error

DeleteObjectVersionByNumber 按从 1 开始的版本号永久删除指定对象历史版本。

func (*Client) DeleteObjectVersions added in v0.0.3

func (c *Client) DeleteObjectVersions(
	ctx context.Context,
	bucket string,
	versions []ObjectVersionIdentifier,
) error

DeleteObjectVersions 按 VersionID 批量删除对象历史版本,并自动按 S3 1000 个对象限制分批。

func (*Client) DeleteObjectVersionsByNumber added in v0.0.3

func (c *Client) DeleteObjectVersionsByNumber(
	ctx context.Context,
	bucket string,
	versions []ObjectVersionNumberIdentifier,
) error

DeleteObjectVersionsByNumber 按版本号批量删除对象历史版本,并自动按 S3 1000 个对象限制分批。

func (*Client) DeleteObjects

func (c *Client) DeleteObjects(ctx context.Context, bucket string, keys []string) error

DeleteObjects deletes objects in batches that respect the S3 1000-key limit.

func (*Client) DownloadFile

func (c *Client) DownloadFile(ctx context.Context, bucket, key, localPath string) error

DownloadFile downloads an object atomically by writing to a temporary file and renaming it on success.

func (*Client) DownloadFileVersion added in v0.0.3

func (c *Client) DownloadFileVersion(ctx context.Context, bucket, key, localPath, versionID string) error

DownloadFileVersion 按 VersionID 原子下载对象历史版本,成功后再重命名临时文件。

func (*Client) DownloadFileVersionByNumber added in v0.0.3

func (c *Client) DownloadFileVersionByNumber(
	ctx context.Context,
	bucket string,
	key string,
	localPath string,
	versionNumber int,
) error

DownloadFileVersionByNumber 按从 1 开始的版本号原子下载对象历史版本。 版本号 1 表示最新对象版本。

func (*Client) EmptyBucket

func (c *Client) EmptyBucket(ctx context.Context, bucket string) error

EmptyBucket deletes every object in a bucket.

func (*Client) EmptyBucketVersions added in v0.0.3

func (c *Client) EmptyBucketVersions(ctx context.Context, bucket string) error

EmptyBucketVersions 永久删除版本桶里的所有对象历史版本和删除标记。

func (*Client) GetObject

func (c *Client) GetObject(ctx context.Context, bucket, key string) (io.ReadCloser, error)

GetObject fetches an object body. The caller must close the returned reader.

func (*Client) GetObjectBytes

func (c *Client) GetObjectBytes(ctx context.Context, bucket, key string) ([]byte, error)

GetObjectBytes fetches an object into memory.

func (*Client) GetObjectVersion added in v0.0.3

func (c *Client) GetObjectVersion(ctx context.Context, bucket, key, versionID string) (io.ReadCloser, error)

GetObjectVersion 按 VersionID 读取对象的指定历史版本。 调用方必须关闭返回的 reader。

func (*Client) GetObjectVersionByNumber added in v0.0.3

func (c *Client) GetObjectVersionByNumber(
	ctx context.Context,
	bucket string,
	key string,
	versionNumber int,
) (io.ReadCloser, error)

GetObjectVersionByNumber 按从 1 开始的版本号读取对象历史版本。 版本号 1 表示最新对象版本;调用方必须关闭返回的 reader。

func (*Client) GetObjectVersionBytes added in v0.0.3

func (c *Client) GetObjectVersionBytes(ctx context.Context, bucket, key, versionID string) ([]byte, error)

GetObjectVersionBytes 按 VersionID 将对象历史版本读取到内存。

func (*Client) GetObjectVersionBytesByNumber added in v0.0.3

func (c *Client) GetObjectVersionBytesByNumber(
	ctx context.Context,
	bucket string,
	key string,
	versionNumber int,
) ([]byte, error)

GetObjectVersionBytesByNumber 按从 1 开始的版本号将对象历史版本读取到内存。 版本号 1 表示最新对象版本。

func (*Client) ListBuckets

func (c *Client) ListBuckets(ctx context.Context) ([]string, error)

ListBuckets lists all visible bucket names.

func (*Client) ListObjectVersions added in v0.0.3

func (c *Client) ListObjectVersions(ctx context.Context, bucket, key string) ([]ObjectVersion, error)

ListObjectVersions 列出单个对象 key 的所有可读取历史版本。

返回的 VersionNumber 从 1 开始:1 表示最新对象版本,2 表示上一个对象版本。 删除标记不可作为文件内容读取,因此不会出现在返回结果里。

func (*Client) ListObjects

func (c *Client) ListObjects(ctx context.Context, bucket, prefix string) ([]string, error)

ListObjects lists all object keys under prefix.

func (*Client) MoveObject

func (c *Client) MoveObject(ctx context.Context, bucket, srcKey, dstKey string) error

MoveObject copies an object and removes the source key.

func (*Client) MoveObjectVersion added in v0.0.3

func (c *Client) MoveObjectVersion(
	ctx context.Context,
	bucket string,
	srcKey string,
	srcVersionID string,
	dstKey string,
) (string, error)

MoveObjectVersion 按 VersionID 将源对象历史版本移动到新 key。 该方法会先复制该历史版本,再永久删除源 VersionID;目标桶启用版本控制时返回新 VersionID。

func (*Client) MoveObjectVersionByNumber added in v0.0.3

func (c *Client) MoveObjectVersionByNumber(
	ctx context.Context,
	bucket string,
	srcKey string,
	versionNumber int,
	dstKey string,
) (string, error)

MoveObjectVersionByNumber 按从 1 开始的版本号将源对象历史版本移动到新 key。

func (*Client) ObjectExists

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

ObjectExists reports whether an object exists.

func (*Client) ObjectVersionExists added in v0.0.3

func (c *Client) ObjectVersionExists(ctx context.Context, bucket, key, versionID string) (bool, error)

ObjectVersionExists 判断指定 VersionID 的对象历史版本是否存在。

func (*Client) ObjectVersionExistsByNumber added in v0.0.3

func (c *Client) ObjectVersionExistsByNumber(
	ctx context.Context,
	bucket string,
	key string,
	versionNumber int,
) (bool, error)

ObjectVersionExistsByNumber 判断指定版本号的对象历史版本是否存在。

func (*Client) ObjectVersionID added in v0.0.3

func (c *Client) ObjectVersionID(ctx context.Context, bucket, key string, versionNumber int) (string, error)

ObjectVersionID 将从 1 开始的版本号解析为 S3 的 VersionID。 版本号 1 表示最新对象版本。

func (*Client) PresignGetObject

func (c *Client) PresignGetObject(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)

PresignGetObject creates a pre-signed GET URL.

func (*Client) PresignGetObjectVersion added in v0.0.3

func (c *Client) PresignGetObjectVersion(
	ctx context.Context,
	bucket string,
	key string,
	versionID string,
	expiry time.Duration,
) (string, error)

PresignGetObjectVersion 按 VersionID 创建对象历史版本的预签名 GET URL。

func (*Client) PresignGetObjectVersionByNumber added in v0.0.3

func (c *Client) PresignGetObjectVersionByNumber(
	ctx context.Context,
	bucket string,
	key string,
	versionNumber int,
	expiry time.Duration,
) (string, error)

PresignGetObjectVersionByNumber 按从 1 开始的版本号创建对象历史版本的预签名 GET URL。

func (*Client) PresignPutObject

func (c *Client) PresignPutObject(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)

PresignPutObject creates a pre-signed PUT URL.

func (*Client) PutObject

func (c *Client) PutObject(ctx context.Context, bucket, key string, body io.Reader, contentType string) error

PutObject uploads data from body to the given bucket and key.

func (*Client) PutObjectBytes

func (c *Client) PutObjectBytes(ctx context.Context, bucket, key string, data []byte, contentType string) error

PutObjectBytes uploads an in-memory byte slice.

func (*Client) PutObjectBytesSnowballAutoExtract added in v0.0.4

func (c *Client) PutObjectBytesSnowballAutoExtract(
	ctx context.Context,
	bucket string,
	key string,
	data []byte,
	contentType string,
) error

PutObjectBytesSnowballAutoExtract uploads an in-memory archive and asks MinIO to extract it server-side.

func (*Client) PutObjectBytesVersion added in v0.0.3

func (c *Client) PutObjectBytesVersion(
	ctx context.Context,
	bucket string,
	key string,
	data []byte,
	contentType string,
) (string, error)

PutObjectBytesVersion 上传内存字节切片并在桶启用版本控制时返回新对象的 VersionID。

func (*Client) PutObjectSnowballAutoExtract added in v0.0.4

func (c *Client) PutObjectSnowballAutoExtract(
	ctx context.Context,
	bucket string,
	key string,
	body io.Reader,
	contentType string,
) error

PutObjectSnowballAutoExtract uploads an archive and asks MinIO to extract it server-side by sending x-amz-meta-snowball-auto-extract: true.

This is a MinIO-specific extension for .tar, .tgz, and .zip bulk imports. Other S3-compatible services may store the metadata without extracting.

func (*Client) PutObjectVersion added in v0.0.3

func (c *Client) PutObjectVersion(
	ctx context.Context,
	bucket string,
	key string,
	body io.Reader,
	contentType string,
) (string, error)

PutObjectVersion 上传对象并在桶启用版本控制时返回新对象的 VersionID。

func (*Client) UploadFile

func (c *Client) UploadFile(ctx context.Context, bucket, key, localPath string) error

UploadFile uploads a local file and infers its content type from the file extension.

func (*Client) UploadFileSnowballAutoExtract added in v0.0.4

func (c *Client) UploadFileSnowballAutoExtract(ctx context.Context, bucket, key, localPath string) error

UploadFileSnowballAutoExtract uploads a .tar, .tgz, or .zip archive and asks MinIO to extract it server-side by sending x-amz-meta-snowball-auto-extract: true.

This optimizes bulk imports of many small files into MinIO. It is not a portable S3 standard; non-MinIO services may store the archive as a normal object with user metadata and perform no extraction.

func (*Client) UploadFileVersion added in v0.0.3

func (c *Client) UploadFileVersion(ctx context.Context, bucket, key, localPath string) (string, error)

UploadFileVersion 上传本地文件并在桶启用版本控制时返回新对象的 VersionID。

func (*Client) WaitBucketExists

func (c *Client) WaitBucketExists(ctx context.Context, name string, timeout time.Duration) error

WaitBucketExists blocks until the bucket exists or the timeout expires.

type Config

type Config struct {
	// Endpoint is the base URL of the S3-compatible service. Leave it empty to
	// use the default AWS S3 endpoint resolution for the selected Region.
	Endpoint string
	// AccessKeyID is the static access key to use. Leave it empty to use the
	// default AWS credential chain.
	AccessKeyID string
	// SecretAccessKey is the static secret key to use. It must be paired with
	// AccessKeyID when set.
	SecretAccessKey string
	// SessionToken is an optional session token for temporary static
	// credentials.
	SessionToken string
	// Region is the AWS region or S3-compatible region name. It defaults to
	// us-east-1 when omitted.
	Region string
}

Config configures a Client.

If AccessKeyID and SecretAccessKey are left empty, s3kit uses the AWS SDK v2 default credential chain. When Endpoint is set, s3kit assumes a generic S3-compatible service and enables path-style addressing automatically.

type ObjectVersion added in v0.0.3

type ObjectVersion struct {
	VersionNumber int
	VersionID     string
	IsLatest      bool
	LastModified  time.Time
	Size          int64
	ETag          string
}

ObjectVersion 描述对象的一个可读取历史版本。

VersionNumber 使用从 1 开始的序号:1 表示最新对象版本,2 表示上一个对象版本,以此类推。

type ObjectVersionIdentifier added in v0.0.3

type ObjectVersionIdentifier struct {
	Key       string
	VersionID string
}

ObjectVersionIdentifier 标识一个指定 VersionID 的对象历史版本。

type ObjectVersionNumberIdentifier added in v0.0.3

type ObjectVersionNumberIdentifier struct {
	Key           string
	VersionNumber int
}

ObjectVersionNumberIdentifier 标识一个指定版本号的对象历史版本。

type SnowballAutoExtractTransferOptions added in v0.0.4

type SnowballAutoExtractTransferOptions struct {
	// SourceBucket and SourceKey identify the remote archive object to read when
	// SourceURL is empty.
	SourceBucket string
	SourceKey    string
	// SourceURL is an optional HTTP(S) or presigned S3 URL. When set,
	// SourceBucket is not required and source may be nil.
	SourceURL string
	// DestinationBucket and DestinationKey identify where the archive is
	// uploaded on the MinIO target.
	DestinationBucket string
	DestinationKey    string
	// ContentType optionally overrides the uploaded archive content type. Leave
	// empty to infer from SourceKey or SourceURL.
	ContentType string
}

SnowballAutoExtractTransferOptions configures TransferSnowballAutoExtract.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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