Documentation
¶
Overview ¶
Package blobstore keeps opaque byte payloads (audio, images, video) outside the database. A Store addresses blobs by key; the metadata that makes a blob meaningful (content type, owner, expiry) lives in internal/mediastore.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("blob not found")
ErrNotFound reports a key with no blob behind it.
Functions ¶
func ValidateKey ¶
ValidateKey accepts keys made of slash-separated segments of [A-Za-z0-9._-], none empty and none "." or "..", so every key is safe to join under a root directory and stays portable across filesystems and object stores.
Types ¶
type Filesystem ¶
type Filesystem struct {
// contains filtered or unexported fields
}
Filesystem stores each blob as a file under a root directory, at the path its key spells. Writes land in a temporary file beside the target and are renamed into place on commit, so a reader never sees a partial blob and a crash mid-write leaves nothing but a stray temp file.
func NewFilesystem ¶
func NewFilesystem(root string) (*Filesystem, error)
NewFilesystem creates the root directory if needed and returns a store rooted there.
func (*Filesystem) Close ¶
func (s *Filesystem) Close() error
Close is a no-op; files need no teardown.
func (*Filesystem) Delete ¶
func (s *Filesystem) Delete(_ context.Context, key string) error
Delete removes the blob's file and any directories it leaves empty, up to the root, so date-partitioned keys do not accumulate empty folders.
func (*Filesystem) Open ¶
func (s *Filesystem) Open(_ context.Context, key string) (io.ReadSeekCloser, error)
Open returns the blob's file.
func (*Filesystem) Root ¶
func (s *Filesystem) Root() string
Root is the absolute directory blobs live under.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory keeps blobs in process memory. It backs tests and the `memory` media storage type; nothing survives a restart.
type Store ¶
type Store interface {
// Create opens a writer for key. The blob becomes visible only when the
// writer is committed; closing an uncommitted writer discards what was
// written. An existing blob at key is replaced on commit. A Commit that
// fails after the blob became visible leaves it in place, because the
// writer cannot know whether it replaced another writer's blob; a caller
// that owns the key and wants nothing left there calls Delete.
Create(ctx context.Context, key string) (Writer, error)
// Open returns the blob at key for reading. It is the caller's job to
// close the reader.
Open(ctx context.Context, key string) (io.ReadSeekCloser, error)
// Delete removes the blob at key. A missing blob is not an error.
Delete(ctx context.Context, key string) error
// Close releases backend resources.
Close() error
}
Store persists blobs by key.