Documentation ¶
Overview ¶
Package s3util defines some helpful utilities for working with S3.
Index ¶
- func BucketRegion(ctx context.Context, bucket string) (string, error)
- func IsNotExist(err error) bool
- type Client
- func (c *Client) Get(ctx context.Context, key string) (io.ReadCloser, error)
- func (c *Client) GetData(ctx context.Context, key string) ([]byte, error)
- func (c *Client) Put(ctx context.Context, key string, data io.Reader) error
- func (c *Client) PutCond(ctx context.Context, key, etag string, data io.Reader) (written bool, _ error)
- type ETagReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BucketRegion ¶
BucketRegion reports the specified region for the given bucket using the GetBucketLocation API.
func IsNotExist ¶
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 ¶
Client is a wrapper for an S3 client that provides basic read and write facilities to a specific bucket.
func (*Client) Get ¶
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 ¶
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) 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.