blobstore

package
v0.1.96 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 10 Imported by: 0

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

View Source
var ErrNotFound = errors.New("blob not found")

ErrNotFound reports a key with no blob behind it.

Functions

func Put

func Put(ctx context.Context, store Store, key string, r io.Reader) (int64, error)

Put stores everything r yields under key and reports the byte count.

func ValidateKey

func ValidateKey(key string) error

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) Create

func (s *Filesystem) Create(_ context.Context, key string) (Writer, error)

Create opens a temporary file next to the target path.

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.

func NewMemory

func NewMemory() *Memory

NewMemory returns an empty in-memory store.

func (*Memory) Close

func (s *Memory) Close() error

Close is a no-op.

func (*Memory) Create

func (s *Memory) Create(_ context.Context, key string) (Writer, error)

Create returns a writer that publishes its buffer on commit.

func (*Memory) Delete

func (s *Memory) Delete(_ context.Context, key string) error

Delete forgets the blob.

func (*Memory) Len

func (s *Memory) Len() int

Len reports how many blobs are stored; tests use it to check sweeps.

func (*Memory) Open

func (s *Memory) Open(_ context.Context, key string) (io.ReadSeekCloser, error)

Open returns a reader over a copy of the blob.

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.

type Writer

type Writer interface {
	io.Writer
	Commit() error
	Close() error
}

Writer receives one blob. Commit publishes it; Close without a prior Commit discards it. Both are safe to call more than once, and Close after Commit is a no-op, so `defer w.Close()` is the right shape for callers.

Jump to

Keyboard shortcuts

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