s3util

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package s3util defines some helpful utilities for working with S3.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BucketRegion

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

BucketRegion reports the specified region for the given bucket using the GetBucketLocation API.

func IsNotExist

func IsNotExist(err error) bool

IsNotExist reports whether err is an error indicating the requested resource was not found, taking into account S3 and standard library types.

Types

type Client

type Client struct {
	Client *s3.Client
	Bucket string
}

Client is a wrapper for an S3 client that provides basic read and write facilities to a specific bucket.

func (*Client) Get

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

Get returns the contents of the specified key from S3. On success, the returned reader contains the contents of the object, and the caller must close the reader when finished.

If the key is not found, the resulting error satisfies fs.ErrNotExist.

func (*Client) GetData

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

GetData returns the contents of the specified key from S3. It is a shorthand for calling Get followed by io.ReadAll on the result.

func (*Client) Put

func (c *Client) Put(ctx context.Context, key string, data io.Reader) error

Put writes the specified data to S3 under the given key.

func (*Client) PutCond

func (c *Client) PutCond(ctx context.Context, key, etag string, data io.Reader) (written bool, _ error)

PutCond writes the specified data to S3 under the given key if the key does not already exist, or if its content differs from the given etag. The etag is an MD5 of the expected contents, encoded as lowercase hex digits. On success, written reports whether the object was written.

type ETagReader

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

ETagReader implements the io.Reader interface by delegating to a nested reader. The ETag method returns a correctly-formatted S3 ETag for all the data that have been read so far (initially none).

func NewETagReader

func NewETagReader(r io.Reader) ETagReader

NewETagReader returns a new S3 ETag reader for the contents of r.

func (ETagReader) ETag

func (e ETagReader) ETag() string

ETag returns a correctly-formatted S3 etag for the contents of e that have been read so far.

func (ETagReader) Read

func (e ETagReader) Read(data []byte) (int, error)

Read satisfies io.Reader by delegating to the wrapped reader.

Jump to

Keyboard shortcuts

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