storage

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidKey = errors.New("storage: invalid object key")

ErrInvalidKey is returned for a key that isn't a sha256 content address (64 lowercase hex chars). Backends check this before touching the filesystem or bucket so a bad key from a drifted DB row fails cleanly.

Functions

This section is empty.

Types

type Local

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

Local stores objects on the local filesystem under root, sharded by the first two hex chars of the sha256 to keep directories small.

func NewLocal

func NewLocal(root string) (*Local, error)

func (*Local) Delete

func (l *Local) Delete(_ context.Context, key string) error

func (*Local) Exists

func (l *Local) Exists(_ context.Context, key string) (bool, error)

func (*Local) Get

func (l *Local) Get(_ context.Context, key string) (io.ReadCloser, int64, error)

func (*Local) List

func (l *Local) List(ctx context.Context, fn func(ObjectInfo) error) error

List walks the shard directories. In-flight uploads (".upload-*" temp files in the root) are not objects yet and are skipped.

func (*Local) Put

func (l *Local) Put(_ context.Context, r io.Reader) (Object, error)

type Object

type Object struct {
	Key    string // backend-defined; for Local it is the sha256 hex
	Size   int64
	SHA256 string
}

Object is the metadata returned after writing to storage.

type ObjectInfo

type ObjectInfo struct {
	Key     string
	Size    int64
	ModTime time.Time
}

ObjectInfo describes a stored object as reported by List.

type S3

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

S3 stores objects in an S3-compatible bucket, keyed by content sha256 (same content-addressing + dedup contract as Local). Durability is the bucket's responsibility — see PLAN.md ("Storage: do we need erasure coding?").

func NewS3

func NewS3(ctx context.Context, cfg S3Config) (*S3, error)

NewS3 builds the client and ensures the bucket exists. It retries the initial reach for ~30s so it tolerates being started alongside the S3 server (compose) before it is accepting connections.

func (*S3) Delete

func (s *S3) Delete(ctx context.Context, key string) error

func (*S3) Exists

func (s *S3) Exists(ctx context.Context, key string) (bool, error)

func (*S3) Get

func (s *S3) Get(ctx context.Context, key string) (io.ReadCloser, int64, error)

func (*S3) List

func (s *S3) List(ctx context.Context, fn func(ObjectInfo) error) error

func (*S3) Put

func (s *S3) Put(ctx context.Context, r io.Reader) (Object, error)

Put streams r to a temp file while hashing, so the object can be keyed by its content sha256 without buffering the whole (up to 500 MiB) blob in memory. Dedups: if an object with that key already exists, the upload is skipped.

type S3Config

type S3Config struct {
	Endpoint  string // host:port, no scheme (e.g. "rustfs:9000")
	AccessKey string
	SecretKey string
	Bucket    string
	UseSSL    bool
}

S3Config configures the S3-backed Storage. Works against RustFS (compose), AWS S3, Cloudflare R2, Backblaze B2, SeaweedFS — anything S3-API-compatible. minio-go is used purely as a generic S3 client.

type Storage

type Storage interface {
	// Put streams r to storage, computing sha256 in flight, and deduplicates
	// by content hash. Returns the resulting Object whose Key can be used
	// with Get.
	Put(ctx context.Context, r io.Reader) (Object, error)
	// Get opens the object for key and reports its size in bytes, so callers
	// can set a Content-Length that matches the bytes they're about to stream
	// rather than trusting a separately-stored size that may have drifted.
	// Returns fs.ErrNotExist if the key is absent. Get, Delete and Exists
	// return ErrInvalidKey for a key that isn't a sha256 hex digest.
	Get(ctx context.Context, key string) (io.ReadCloser, int64, error)
	Delete(ctx context.Context, key string) error
	Exists(ctx context.Context, key string) (bool, error)
	// List calls fn for every stored object, in no particular order, stopping
	// at the first error fn returns. Used by blob garbage collection.
	List(ctx context.Context, fn func(ObjectInfo) error) error
}

Storage is a content-addressable blob interface. Implementations are responsible for durability — callers do not request replication or erasure-coding. See PLAN.md ("Storage: do we need erasure coding?").

Jump to

Keyboard shortcuts

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