blob

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: Apache-2.0, MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBlobTooLarge = errors.New("blob size exceeds the maximum allowed")
	ErrBlobNotFound = errors.New("no blob is found with given ID")
)

Functions

This section is empty.

Types

type Descriptor

type Descriptor struct {
	// ID is the blob identifier.
	ID ID
	// Size is the size of blob in bytes.
	Size uint64
	// ModificationTime is the latest time at which the blob was modified.
	ModificationTime time.Time
	Status           *Status
}

Descriptor describes a created blob.

type ID

type ID uuid.UUID

ID uniquely identifies a blob.

func NewID

func NewID() (*ID, error)

NewID instantiates a new randomly generated ID.

func (*ID) Decode

func (i *ID) Decode(v string) error

Decode instantiates the ID from the decoded string value.

func (*ID) String

func (i *ID) String() string

String returns the string representation of ID.

type LocalStore

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

LocalStore is a Store that stores blobs as flat files in a configured directory. Blobs are stored as flat files, named by their ID with .bin extension. This store is used primarily for testing purposes.

func NewLocalStore

func NewLocalStore(dir string) *LocalStore

NewLocalStore instantiates a new LocalStore and uses the given dir as the place to store blobs. Blobs are stored as flat files, named by their ID with .bin extension.

func (*LocalStore) Describe

func (l *LocalStore) Describe(ctx context.Context, id ID) (*Descriptor, error)

Describe gets the description of the blob for the given id. If no blob is found for the given id, ErrBlobNotFound is returned.

func (*LocalStore) Dir

func (l *LocalStore) Dir() string

Dir returns the local directory path used by the store.

func (*LocalStore) Get

func (l *LocalStore) Get(_ context.Context, id ID) (io.ReadSeekCloser, error)

Get Retrieves the content of blob. If no blob is found for the given id, ErrBlobNotFound is returned.

func (*LocalStore) Put

func (l *LocalStore) Put(_ context.Context, reader io.ReadCloser) (*Descriptor, error)

Put reads the given reader fully and stores its content in the store directory as flat files. The reader content is first stored in a temporary directory and upon successful storage is moved to the store directory. The Descriptor.ModificationTime is set to the modification date of the file that corresponds to the content. The Descriptor.ID is randomly generated; see NewID.

type Replica

type Replica struct {
	Provider     string
	Status       string
	LastVerified time.Time
	Expiration   time.Time
}

type Status

type Status struct {
	Replicas []Replica
}

type Store

type Store interface {
	Put(context.Context, io.ReadCloser) (*Descriptor, error)
	Describe(context.Context, ID) (*Descriptor, error)
	Get(context.Context, ID) (io.ReadSeekCloser, error)
}

Jump to

Keyboard shortcuts

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