s3

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2025 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMajorFailure is returned when an unexpected serious error occurred.  Contact the development team.
	ErrMajorFailure = errors.New("major failure")
	// ErrNoAccess is returned when the access to the object or bucket is not available.
	ErrNoAccess = errors.New("no access")
)

Functions

func Base

func Base(path string) string

Base returns the last element of `path`. Trailing path separators are removed before extracting the last element. If the path is empty, Base returns "."

func GetClient

func GetClient(path string, opts ...Option) (*awsS3.Client, error)

GetClient returns a client for the bucket of `path`. It handles the option WithProfile.

func HasAccess

func HasAccess(ctx context.Context, path string, opts ...Option) bool

HasAccess returns true if the object or prefix at`path`can be accessed even if it does not yet exist.

It supports the option WithProfile, and WithRetry.

func IsDir

func IsDir(ctx context.Context, path string, opts ...Option) bool

IsDir informs whether the path is a key with objects. The path may end with "/". The root of an accessible bucket is a directory.

If the bucket is not accessible, it returns false.

func IsWithRetry

func IsWithRetry(opts ...Option) bool

IsWithRetry returns true if the option is set to use a retry strategy.

func Join

func Join(elems ...string) string

Join joins any number of path elements into a single s3URI. If the argument list is empty, Join returns an empty string. If an elems is "", it is skipped. The function supports ".." path elements.

func Parse

func Parse(path string) (string, string)

Parse returns the bucket name and the key of `path`

func ReadDir

func ReadDir(ctx context.Context, path string, opts ...Option) ([]fs.DirEntry, error)

ReadDir lists all the keys in the path. It returns a slice of `fs.DirEntry`. It hides the pagination, i.e., it may return more than 1,000 objects. This version is really compliant with fs.DirEntry. In ReadDir fs.DirEntry.Name() does not return the base.

func Size

func Size(ctx context.Context, path string, opts ...Option) (int64, error)

Size returns the size of the object located at `path`.

It supports the option WithProfile.

Types

type DirEntry

type DirEntry struct {
	InfoDir
	// contains filtered or unexported fields
}

DirEntry is an entry read from a directory. It implements the fs.DirEntry interface.

func (*DirEntry) Info

func (de *DirEntry) Info() (fs.FileInfo, error)

Info returns the FileInfo for the file or subdirectory described by the entry.

func (*DirEntry) IsDir

func (de *DirEntry) IsDir() bool

IsDir reports whether the entry describes a directory.

func (*DirEntry) ModTime

func (de *DirEntry) ModTime() time.Time

ModTime returns the modification time of the entry.

func (*DirEntry) Mode

func (de *DirEntry) Mode() fs.FileMode

Mode systematically returns fs.ModeIrregular. It is necessary for fs.DirEntry interface compliance.

func (*DirEntry) Name

func (de *DirEntry) Name() string

Name returns the name of the file (or subdirectory) described by the entry.

func (*DirEntry) Size

func (de *DirEntry) Size() int64

Size returns the size of the entry.

func (*DirEntry) Sys

func (de *DirEntry) Sys() interface{}

Sys returns. It is needed for fs.DirEntry interface compliance.

func (*DirEntry) Type

func (de *DirEntry) Type() fs.FileMode

Type returns systematically fs.ModeIrregular. Need for fs.DirEntry interface compliance.

type InfoDir

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

InfoDir holds information about S3 repertory.

func (InfoDir) Bucket

func (id InfoDir) Bucket() string

Bucket returns the name of the bucket. The name does not have the prefix "s3://"

func (InfoDir) CreationDate

func (id InfoDir) CreationDate() time.Time

CreationDate returns the creation of the repertory.

func (InfoDir) IsDir

func (id InfoDir) IsDir() bool

IsDir receiver is true if the information is related to a key that points to a "subdirectory".

func (InfoDir) Name

func (id InfoDir) Name() string

Name returns the name of the object without the bucket.

type ObjectInfo

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

ObjectInfo holds the information related to an S3 object. It implements the interface io/fs/FileInfo.

func Info

func Info(ctx context.Context, path string, opts ...Option) (*ObjectInfo, error)

Info returns the ObjectInfo of the object at `path`. If it is a directory, then IsDir() is true and Size() and ModTime() is meaningless.

func (*ObjectInfo) Bucket

func (oi *ObjectInfo) Bucket() string

Bucket returns the name of the bucket holding the object.

func (*ObjectInfo) IsDir

func (oi *ObjectInfo) IsDir() bool

IsDir determines if the given ObjectInfo represents a directory based on its bucket and key attributes.

func (*ObjectInfo) LastModified

func (oi *ObjectInfo) LastModified() time.Time

LastModified returns the last modification date of the object.

func (*ObjectInfo) ModTime

func (oi *ObjectInfo) ModTime() time.Time

ModTime returns the last modification time of the object.

func (*ObjectInfo) Mode

func (oi *ObjectInfo) Mode() fs.FileMode

Mode is mandatory for the fs.FileInfo interface.

func (*ObjectInfo) Name

func (oi *ObjectInfo) Name() string

Name returns the base name of the object as defined by fs.FileInfo.

func (*ObjectInfo) Path

func (oi *ObjectInfo) Path() string

Path returns the path of the object without the bucket.

func (*ObjectInfo) Size

func (oi *ObjectInfo) Size() int64

Size returns the size of the object.

func (*ObjectInfo) StorageClass

func (oi *ObjectInfo) StorageClass() string

StorageClass returns the storage class of the object. It has one of the following values: "STANDARD", "REDUCED_REDUNDANCY", "GLACIER", "STANDARD_IA", "ONEZONE_IA", "INTELLIGENT_TIERING", "DEEP_ARCHIVE", "OUTPOSTS", or "GLACIER_IR".

func (*ObjectInfo) Sys

func (oi *ObjectInfo) Sys() any

Sys is a placeholder method to satisfy the fs.FileInfo interface, always returning nil.

type Option

type Option func(opts *options)

Option allows parameterizing a function

func WithProfile

func WithProfile(p string) Option

WithProfile indicates the operation should use the profile `p`

func WithRetry

func WithRetry(maxAtt int, lapse time.Duration, trigger ...string) Option

WithRetry indicates that the operation must use a retry strategy with a maximum number of attempts `max` with a minimal delay `lapse`

Jump to

Keyboard shortcuts

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