Documentation ¶
Overview ¶
Package stream provides a Golang file system abstraction tailored for AWS S3, enabling seamless streaming of binary objects along with their corresponding metadata. The package implements [Golang File System](https://pkg.go.dev/io/fs) and enhances it by adding support for writable files and type-safe metadata.
Index ¶
- Variables
- func IsValidDir(path string) bool
- func IsValidFile(path string) bool
- func IsValidPath(path string) bool
- func RequireValidDir(ctx, path string) error
- func RequireValidFile(ctx, path string) error
- func RequireValidPath(ctx, path string) error
- type Canceler
- type CopyFS
- type CreateFS
- type File
- type FileSystem
- func (fsys *FileSystem[T]) Copy(source, target string) error
- func (fsys *FileSystem[T]) Create(path string, attr *T) (File, error)
- func (fsys *FileSystem[T]) Glob(pattern string) ([]string, error)
- func (fsys *FileSystem[T]) Open(path string) (fs.File, error)
- func (fsys *FileSystem[T]) ReadDir(path string) ([]fs.DirEntry, error)
- func (fsys *FileSystem[T]) Remove(path string) error
- func (fsys *FileSystem[T]) Stat(path string) (fs.FileInfo, error)
- func (fsys *FileSystem[T]) StatSys(stat fs.FileInfo) *T
- func (fsys *FileSystem[T]) Wait(path string, timeout time.Duration) error
- type Option
- type Opts
- type PreSignedUrl
- type RemoveFS
- type S3
- type S3Signer
- type S3Upload
- type Stat
- type SystemMetadata
Constants ¶
This section is empty.
Variables ¶
var ( // Set S3 client for the file system WithS3 = opts.ForType[Opts, S3]() // Set S3 upload client for the file system WithS3Upload = opts.ForType[Opts, S3Upload]() // Set S3 url signer client for the file system WithS3Signer = opts.ForType[Opts, S3Signer]() // Use aws.Config as base config for S3, S3 upload and S3 url signer clients WithConfig = opts.FMap(optsFromConfig) // Use region for configuring the service WithRegion = opts.FMap(optsFromRegion) // Use default aws.Config for all S3 clients WithDefaultS3 = opts.From(optsDefaultS3) // Sets the I/O timeout for the file stream. // This timeout defines how long the stream remains open. // After timeout expiration any stream I/O would fail. WithIOTimeout = opts.ForName[Opts, time.Duration]("timeout") // Sets the time-to-live for the pre-signed urls WithPreSignUrlTTL = opts.ForName[Opts, time.Duration]("ttlSignedUrl") // Set the number of keys to be read from S3 while walking through "dir" WithListingLimit = opts.ForName[Opts, int32]("lslimit") )
Functions ¶
func IsValidDir ¶ added in v1.1.0
The file system emulates "dirs" as any valid path ending with "/"
func IsValidFile ¶ added in v1.1.0
The file system requires absolute path starting from "/" The file should not end with "/"
func IsValidPath ¶ added in v1.1.0
The file system requires absolute path starting from "/"
func RequireValidFile ¶ added in v1.1.0
Validate file path
Types ¶
type Canceler ¶ added in v1.2.0
type Canceler interface {
Cancel() error
}
Cancel effect of file system i/o, before file is closed.
type CopyFS ¶ added in v1.0.0
type CopyFS interface { fs.FS Copy(source, target string) error Wait(path string, timeout time.Duration) error }
File System extension supporting file copying
type FileSystem ¶ added in v1.0.0
File System
func New ¶ added in v1.0.0
func New[T any](bucket string, opt ...Option) (*FileSystem[T], error)
Create a file system instance, mounting S3 Bucket. Use Option type to configure file system.
func NewFS ¶ added in v1.0.0
func NewFS(bucket string, opts ...Option) (*FileSystem[struct{}], error)
Create a file system instance, mounting S3 Bucket. Use Option type to configure file system.
func (*FileSystem[T]) Copy ¶ added in v1.0.0
func (fsys *FileSystem[T]) Copy(source, target string) error
Copy object from source location to the target. The target shall be absolute s3://bucket/key url.
func (*FileSystem[T]) Create ¶ added in v1.0.0
func (fsys *FileSystem[T]) Create(path string, attr *T) (File, error)
To open the file for writing use `Create` function giving the absolute path starting with `/`, the returned file descriptor is a composite of `io.Writer`, `io.Closer` and `stream.Stat`. Utilize Golang's convenient streaming methods to update S3 object seamlessly. Once all bytes are written, it's crucial to close the stream. Failure to do so would cause data loss. The object is considered successfully created on S3 only if all `Write` operations and subsequent `Close` actions are successful.
func (*FileSystem[T]) Glob ¶ added in v1.0.0
func (fsys *FileSystem[T]) Glob(pattern string) ([]string, error)
Glob returns the names of all files matching pattern. The classical file system organize data hierarchically into directories as opposed to the flat storage structure of general purpose AWS S3.
It assumes a directory if the path ends with `/`.
It return path relative to pattern for all found object.
The pattern consists of S3 key prefix Golang regex. Its are split by `|`.
func (*FileSystem[T]) Open ¶ added in v1.0.0
func (fsys *FileSystem[T]) Open(path string) (fs.File, error)
To open the file for reading use `Open` function giving the absolute path starting with `/`, the returned file descriptor is a composite of `io.Reader`, `io.Closer` and `stream.Stat`. Utilize Golang's convenient streaming methods to consume S3 object seamlessly.
func (*FileSystem[T]) ReadDir ¶ added in v1.0.0
func (fsys *FileSystem[T]) ReadDir(path string) ([]fs.DirEntry, error)
Reads the named directory or path prefix. The classical file system organize data hierarchically into directories as opposed to the flat storage structure of general purpose AWS S3.
It assumes a directory if the path ends with `/`.
It return path relative to pattern for all found object.
func (*FileSystem[T]) Remove ¶ added in v1.0.0
func (fsys *FileSystem[T]) Remove(path string) error
Remove object
func (*FileSystem[T]) Stat ¶ added in v1.0.0
func (fsys *FileSystem[T]) Stat(path string) (fs.FileInfo, error)
Stat returns a FileInfo describing the file. File system executes HeadObject S3 API call to obtain metadata.
func (*FileSystem[T]) StatSys ¶ added in v1.0.0
func (fsys *FileSystem[T]) StatSys(stat fs.FileInfo) *T
Returns file metadata of type T embedded into a FileInfo.
type Opts ¶ added in v1.0.0
type Opts struct {
// contains filtered or unexported fields
}
File System Configuration Options
type PreSignedUrl ¶ added in v1.0.0
type PreSignedUrl struct {
PreSignedUrl string
}
Well-known attribute for reading pre-signed Urls of S3 objects
type S3 ¶ added in v1.0.0
type S3 interface { HeadObject(ctx context.Context, params *s3.HeadObjectInput, optFns ...func(*s3.Options)) (*s3.HeadObjectOutput, error) GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error) ListObjectsV2(ctx context.Context, params *s3.ListObjectsV2Input, optFns ...func(*s3.Options)) (*s3.ListObjectsV2Output, error) DeleteObject(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error) CopyObject(ctx context.Context, params *s3.CopyObjectInput, optFns ...func(*s3.Options)) (*s3.CopyObjectOutput, error) }
type S3Signer ¶ added in v1.0.0
type S3Signer interface { PresignGetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.PresignOptions)) (*v4.PresignedHTTPRequest, error) PresignPutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.PresignOptions)) (*v4.PresignedHTTPRequest, error) }
type S3Upload ¶ added in v1.0.0
type S3Upload interface {
Upload(ctx context.Context, input *s3.PutObjectInput, opts ...func(*manager.Uploader)) (*manager.UploadOutput, error)
}