blob

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: Apache-2.0, MIT Imports: 9 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
	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) *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 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.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