Documentation ¶
Overview ¶
Package blob implements an interface and support code for persistent storage of untyped binary blobs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrKeyExists is reported by Put when writing a key that already exists in // the store. ErrKeyExists = errors.New("key already exists") // ErrKeyNotFound is reported by Get or Size when given a key that does not // exist in the store. ErrKeyNotFound = errors.New("key not found") // ErrStopListing is used by a List callback to terminate the listing. ErrStopListing = errors.New("stop listing keys") )
Functions ¶
func IsKeyExists ¶
IsKeyExists reports whether err is or wraps ErrKeyExists.
func IsKeyNotFound ¶
IsKeyNotFound reports whether err or is or wraps ErrKeyNotFound. It is false if err == nil.
func KeyExists ¶
KeyExists returns an ErrKeyExists error reporting that key exists in the store. The concrete type is *blob.KeyError.
func KeyNotFound ¶
KeyNotFound returns an ErrKeyNotFound error reporting that key was not found. The concrete type is *blob.KeyError.
Types ¶
type CAS ¶
type CAS interface { Store // CASPut writes data to a content-addressed blob in the underlying store, // and returns the assigned key. The target key is returned even in case of // error. CASPut(ctx context.Context, data CASPutOptions) (string, error) // CASKey returns the content address of data without modifying the store. // This must be the same value that would be returned by a successful call // to CASPut on data. CASKey(ctx context.Context, opts CASPutOptions) (string, error) }
CAS is an optional interface that a store may implement to support content addressing using a one-way hash.
type CASPutOptions ¶
type CASPutOptions struct { Data []byte // the data to be stored Prefix, Suffix string // a prefix and suffix to add to the computed key }
CASPutOptions are the arguments to the CASPut and CASKey methods of a CAS implementation.
type HashCAS ¶
type HashCAS struct { Store // contains filtered or unexported fields }
A HashCAS is a content-addressable wrapper that adds the CAS methods to a delegated blob.Store.
type KeyError ¶
type KeyError struct { Err error // the underlying error Key string // the key implicated by the error }
KeyError is the concrete type of errors involving a blob key. The caller may type-assert to *blob.KeyError to recover the key.
type PutOptions ¶
type PutOptions struct { Key string // the key to associate with the data Data []byte // the data to write Replace bool // whether to replace an existing value for this key }
PutOptions regulate the behaviour of the Put method of a Store implementation.
type Store ¶
type Store interface { // Get fetches the contents of a blob from the store. If the key is not // found in the store, Get must report an ErrKeyNotFound error. Get(ctx context.Context, key string) ([]byte, error) // Put writes a blob to the store. If the store already contains the // specified key and opts.Replace is true, the existing value is replaced // without error; otherwise Put must report an ErrKeyExists error. Put(ctx context.Context, opts PutOptions) error // Delete atomically removes a blob from the store. If the key is not found // in the store, Delete must report an ErrKeyNotFound error. Delete(ctx context.Context, key string) error // List calls f with each key in the store in lexicographic order, beginning // with the first key greater than or equal to start. If f reports an error // listing stops and List returns. If f reported an ErrStopListing error, // List returns nil; otherwise List returns the error reported by f. List(ctx context.Context, start string, f func(string) error) error // Len reports the number of keys currently in the store. Len(ctx context.Context) (int64, error) // Close allows the store to release any resources held open while in use. // If an implementation has nothing to release, it must return nil. Close(context.Context) error }
A Store represents a mutable blob store in which each blob is identified by a unique, opaque string key. An implementation of Store is permitted (but not required) to report an error from Put when given an empty key. If the implementation cannot store empty keys, it must report ErrKeyNotFound when operating on an empty key.
Implementations of this interface must be safe for concurrent use by multiple goroutines. Moreover, any sequence of operations on a Store that does not overlap with any Delete executions must be linearizable.1
Directories ¶
Path | Synopsis |
---|---|
Package memstore implements the blob.Store interface using a map.
|
Package memstore implements the blob.Store interface using a map. |
Package storetest provides correctness tests for implementations of the blob.Store interface.
|
Package storetest provides correctness tests for implementations of the blob.Store interface. |