blob

package
v0.0.0-...-683b713 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package blob abstracts away blob storage providers, mostly for testing etc.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is a sentinel error returned when a blob is not found.
	ErrNotFound = errors.New("blob: not found")
)

Functions

This section is empty.

Types

type MemoryStore

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

MemoryStore is an in-memory blob store.

func NewInMemory

func NewInMemory() *MemoryStore

NewInMemory creates a new in-memory blob store.

func (*MemoryStore) Delete

func (ms *MemoryStore) Delete(_ context.Context, key string) error

func (*MemoryStore) Get

func (ms *MemoryStore) Get(_ context.Context, key string) (io.ReadCloser, error)

func (*MemoryStore) Put

func (ms *MemoryStore) Put(_ context.Context, key string, r io.Reader) error

func (*MemoryStore) ScanPrefix

func (ms *MemoryStore) ScanPrefix(ctx context.Context, prefix string) iter.Seq2[*Ref, error]

type Prefixed

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

PrefixedStore wraps a blob store and prefixes all keys with a given prefix. Essentially, creates a "subdirectory" in the blob store and pretends it's the root.

func NewPrefixed

func NewPrefixed(inner Store, prefix string) *Prefixed

NewPrefixed creates a new prefixed blob store.

func (*Prefixed) Delete

func (ps *Prefixed) Delete(ctx context.Context, key string) error

func (*Prefixed) Get

func (ps *Prefixed) Get(ctx context.Context, key string) (io.ReadCloser, error)

func (*Prefixed) Put

func (ps *Prefixed) Put(ctx context.Context, key string, r io.Reader) error

func (*Prefixed) ScanPrefix

func (ps *Prefixed) ScanPrefix(ctx context.Context, prefix string) iter.Seq2[*Ref, error]

type Ref

type Ref struct {
	Key          string
	LastModified time.Time
	ETag         string
	Size         int64
}

Ref is a reference to a blob in a store.

type S3Credentials

type S3Credentials struct {
	Region          string // If unset, defaults to "us-east-1"
	Endpoint        string // If unset, defaults to "https://s3.amazonaws.com"
	AccessKeyID     string
	SecretAccessKey string
}

S3Credentials contains the necessary credentials to connect to an S3-compatible storage provider.

type S3Store

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

S3Store is a blob store backed by an S3-compatible storage provider.

func NewS3Store

func NewS3Store(creds *S3Credentials, bucket string) (*S3Store, error)

NewS3Store creates a new S3 blob store from passed credentials.

func (*S3Store) Delete

func (s3s *S3Store) Delete(ctx context.Context, key string) error

func (*S3Store) Get

func (s3s *S3Store) Get(ctx context.Context, key string) (io.ReadCloser, error)

func (*S3Store) Put

func (s3s *S3Store) Put(ctx context.Context, key string, r io.Reader) error

func (*S3Store) ScanPrefix

func (s3s *S3Store) ScanPrefix(ctx context.Context, prefix string) iter.Seq2[*Ref, error]

type Store

type Store interface {
	// Get retrieves a blob from the store by its key.
	// Returns an io.ReadCloser, i.e. caller must close it when done.
	Get(ctx context.Context, key string) (io.ReadCloser, error)

	// Put stores a blob in the store under the given key.
	Put(ctx context.Context, key string, r io.Reader) error

	// Delete removes a blob from the store by its key.
	Delete(ctx context.Context, key string) error

	// ScanPrefix returns an iterator over a prefix of keys.
	// Will continue iterating until the iterator is exhausted, the
	// caller indicates it is done by returning false from the callback,
	// or the context is cancelled.
	ScanPrefix(ctx context.Context, prefix string) iter.Seq2[*Ref, error]
}

Store is a blob storage provider which can be used to store and retrieve blobs of data, identified by a key.

Jump to

Keyboard shortcuts

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