s3util

package
v1.27.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Overview

Package s3util contains helper functions to provide high level interface to S3 storage.

Index

Constants

View Source
const CannotReadError = "cannot read remote object"

CannotReadError is used in the tests.

Variables

This section is empty.

Functions

func CopyObject

func CopyObject(ctx context.Context, client CopyObjectAPIClient, inputBucket, inputKey, outputBucket, outputKey string) error

CopyObject copies the `inputKey` in the inputBucket to `outputKey` in the outputBucket.

func DeleteObject

func DeleteObject(ctx context.Context, client DeleteObjectsAPIClient, bucket, file string) error

DeleteObject delete the key in the specified bucket.

func DeleteObjects added in v1.23.5

func DeleteObjects(ctx context.Context, client DeleteObjectsAPIClient, bucket string, files []string) error

DeleteObjects delete the keys in the specified bucket.

func DownloadObject

func DownloadObject(ctx context.Context, client GetObjectAPIClient, bucket, src string) ([]byte, error)

DownloadObject downloads a file from an S3 bucket given the bucket and key. The response is in slice of byte format.

func ListBucket

func ListBucket(ctx context.Context, client ListObjectsV2APIClient, bucket, prefix, lastKey string, maxKeys int32) ([]string, error)

ListBucket returns a slice of the files at an S3 bucket at a given prefix. It lists the objects using maxKeys in each iteration, but returns all of the objects, which may be higher than maxKeys.

func ListFolders

func ListFolders(ctx context.Context, client ListObjectsV2APIClient, bucket, prefix, lastKey string, maxKeys int32) ([]string, error)

ListFolders returns the folders stored at `prefix` in the bucket `bucket`.

func ListNObjectsInBucket

func ListNObjectsInBucket(ctx context.Context, client ListObjectsV2APIClient, bucket, prefix, lastKey, delimiter string, maxKeys int32) (objects []string, isTruncated bool, err error)

ListNObjectsInBucket returns a slice of the files at an S3 bucket at a given prefix. It starts listing the files from `lastKey` and returns up to `maxKeys`.

func ObjectExists

func ObjectExists(ctx context.Context, client HeadObjectAPIClient, bucket, file string) (bool, error)

ObjectExists returns a boolean of whether the key exists in the bucket.

func RenameObject

func RenameObject(ctx context.Context, client CopyObjectAPIClient, deleteClient DeleteObjectsAPIClient, bucket, inputKey, outputKey string) error

RenameObject renames the `inputKey` in the bucket to `outputKey`.

func UploadObject

func UploadObject(ctx context.Context, client PutObjectAPIClient, bucket, dst string, src []byte) error

UploadObject uploads a slice of bytes to a specific path and S3 bucket.

Types

type CopyObjectAPIClient added in v1.27.0

type CopyObjectAPIClient interface {
	CopyObject(context.Context, *s3.CopyObjectInput, ...func(*s3.Options)) (*s3.CopyObjectOutput, error)
}

CopyObjectAPIClient defines the interface for S3 copy operations

type DeleteObjectsAPIClient added in v1.27.0

type DeleteObjectsAPIClient interface {
	DeleteObject(context.Context, *s3.DeleteObjectInput, ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)
	DeleteObjects(context.Context, *s3.DeleteObjectsInput, ...func(*s3.Options)) (*s3.DeleteObjectsOutput, error)
}

DeleteObjectsAPIClient defines the interface for S3 delete operations

type GetObjectAPIClient added in v1.27.0

type GetObjectAPIClient interface {
	GetObject(context.Context, *s3.GetObjectInput, ...func(*s3.Options)) (*s3.GetObjectOutput, error)
}

GetObjectAPIClient defines the interface for S3 get object operations

type HeadObjectAPIClient added in v1.27.0

type HeadObjectAPIClient interface {
	HeadObject(context.Context, *s3.HeadObjectInput, ...func(*s3.Options)) (*s3.HeadObjectOutput, error)
}

HeadObjectAPIClient defines the interface for S3 head object operations

type ListObjectsV2APIClient added in v1.27.0

type ListObjectsV2APIClient interface {
	ListObjectsV2(context.Context, *s3.ListObjectsV2Input, ...func(*s3.Options)) (*s3.ListObjectsV2Output, error)
}

ListObjectsV2APIClient defines the interface for S3 list objects v2 operations

type PutObjectAPIClient added in v1.27.0

type PutObjectAPIClient interface {
	PutObject(context.Context, *s3.PutObjectInput, ...func(*s3.Options)) (*s3.PutObjectOutput, error)
}

PutObjectAPIClient defines the interface for S3 put object operations

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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