blob

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: Apache-2.0, MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Kib = 1 << (10 * (iota + 1))
	Mib
	Gib
)

Variables

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

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
	Replicas         []Replica
}

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, options ...Option) *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.Reader) (*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.

Before a blob is written, the minimum amount of free space must be available on the local disk. If writing the blob consumes more then the available space (free space - minimum free), then this results in an error.

type Option added in v0.2.3

type Option func(*config)

Option is a function that sets a value in a config.

func WithMinFreeSpace added in v0.2.3

func WithMinFreeSpace(space int64) Option

WithMinFreeSpace seta the minimum amount of free dist space that must remain after writing a blob. If unset or 0 then defaultMinFreeSpace is used. If -1, then no free space checks are performed.

type PassThroughGet added in v0.2.2

type PassThroughGet interface {
	PassGet(http.ResponseWriter, *http.Request, ID)
}

type Piece added in v0.2.2

type Piece struct {
	Expiration  time.Time
	LastUpdated time.Time
	PieceCID    string
	Status      string
}

type Replica

type Replica struct {
	Provider string
	Pieces   []Piece
}

type Store

type Store interface {
	Put(context.Context, io.Reader) (*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