Documentation
¶
Overview ¶
Package blobstore keeps the files ReputeCast stores outside the database (digital products' files, lead magnets, chunked uploads, audience exports) in the local files folder or in an S3-compatible bucket (storage.backend). Both backends name objects with the same keys, so moving from one to the other is a copy (`reputecast storage migrate`).
Index ¶
- Constants
- Variables
- func NewS3Client(ctx context.Context, c config.S3Config) (*s3.Client, error)
- func ValidKey(key string) error
- type CopyOptions
- type CopyStats
- type File
- type Info
- type Local
- func (l Local) Delete(_ context.Context, key string) error
- func (l Local) List(ctx context.Context, prefix string, fn func(key string, info Info) error) error
- func (l Local) Open(_ context.Context, key string) (io.ReadCloser, error)
- func (l Local) OpenRange(_ context.Context, key string, off, n int64) (io.ReadCloser, error)
- func (l Local) Put(ctx context.Context, key string, r io.Reader, size int64, _ string) error
- func (l Local) Stat(_ context.Context, key string) (Info, error)
- type Part
- type S3
- func (s *S3) Bucket() string
- func (s *S3) Check(ctx context.Context) error
- func (s *S3) Delete(ctx context.Context, key string) error
- func (s *S3) List(ctx context.Context, prefix string, fn func(key string, info Info) error) error
- func (s *S3) Open(ctx context.Context, key string) (io.ReadCloser, error)
- func (s *S3) OpenRange(ctx context.Context, key string, off, n int64) (io.ReadCloser, error)
- func (s *S3) Prefix() string
- func (s *S3) Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) error
- func (s *S3) Stat(ctx context.Context, key string) (Info, error)
- type Store
Constants ¶
const MaxKeyBytes = 900
MaxKeyBytes is the longest key (S3's limit, less room for a prefix).
Variables ¶
var ErrNotExist = fs.ErrNotExist
ErrNotExist is what every backend returns for a key that holds no object (errors.Is(err, fs.ErrNotExist) holds too).
var ErrSize = errors.New("blobstore: the content's length isn't the size given")
ErrSize is a Put whose reader holds more or fewer bytes than its size.
Functions ¶
func NewS3Client ¶
NewS3Client builds the S3 client for a bucket's settings: the endpoint and path style of an S3-compatible service, the region, and static keys or else the default AWS credential chain (environment, shared files, an IAM role, IRSA).
Types ¶
type CopyOptions ¶
type CopyOptions struct {
// DryRun counts what would be copied and copies nothing.
DryRun bool
// Verify reads every copy back and compares its SHA-256 with the
// source's; a copy that differs is deleted and counts as failed.
Verify bool
// Workers copy side by side (0: 8).
Workers int
// Failed hears of each object that couldn't be copied (it may be
// called from several goroutines at once).
Failed func(key string, err error)
}
CopyOptions says how Copy copies.
type CopyStats ¶
CopyStats counts a Copy: every object of the source and its bytes; those copied (or, in a dry run, to copy), those the destination holds already at the same size, and those that failed.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File reads a stored object, or several one after the other (an upload's chunks), as one file: in order (io.Reader), from anywhere (io.Seeker, for http.ServeContent's ranges) and at any offset (io.ReaderAt, for an archive's directory). Reading in order holds one ranged request open from where it began; Seek costs nothing until the next Read.
func OpenFile ¶
OpenFile opens an object to read as a File (its size and time from Stat, so a missing key fails here, before anything is sent).
type Local ¶
type Local struct {
Dir string
}
Local keeps objects as files under a folder (files.dir), a key's slashes its subfolders: the layout ReputeCast has always used, so a folder written before object storage existed reads as it is.
func (Local) Delete ¶
Delete removes a key's file and the folders it leaves empty (an upload's, a workspace's), never the files folder itself.
func (Local) List ¶
List walks the folders the prefix reaches into; files being written aren't listed.
type S3 ¶
type S3 struct {
// contains filtered or unexported fields
}
S3 keeps objects in an S3-compatible bucket (AWS S3, MinIO, Cloudflare R2, DigitalOcean Spaces, Backblaze B2, Wasabi…), under the configured prefix. Large objects and objects of unknown size go up in parts.
func (*S3) Put ¶
func (s *S3) Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) error
Put uploads in one request up to 16 MB, in 8 MB parts beyond (and for a reader of unknown size past its first 16 MB); a failed multipart upload is aborted, so nothing is left behind.
type Store ¶
type Store interface {
// Put stores r's bytes under key, replacing what was there. size is
// r's length, or -1 when it isn't known (a reader that ends early or
// runs past size fails the Put, which then stores nothing). A Put is
// atomic: readers see the old object or the new one, never a part.
Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) error
// Open reads an object from its start.
Open(ctx context.Context, key string) (io.ReadCloser, error)
// OpenRange reads at most n bytes from off (n < 0: to the end). A
// range past the end reads nothing.
OpenRange(ctx context.Context, key string, off, n int64) (io.ReadCloser, error)
// Stat reports an object's size and when it was written.
Stat(ctx context.Context, key string) (Info, error)
// Delete removes an object; a key that doesn't exist isn't an error.
Delete(ctx context.Context, key string) error
// List calls fn for every object whose key starts with prefix, in no
// particular order; fn's error stops the walk and is returned.
List(ctx context.Context, prefix string, fn func(key string, info Info) error) error
}
Store keeps objects under slash-separated keys ("<workspace>/ab/<sha256>", "uploads/<id>/000000000000").
Directories
¶
| Path | Synopsis |
|---|---|
|
Package blobstoretest is the contract every blobstore backend passes, and the test bucket integration tests use.
|
Package blobstoretest is the contract every blobstore backend passes, and the test bucket integration tests use. |