Documentation
¶
Overview ¶
Package kvs implements a write-once key-value store with different storage backends.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned if a key does not exist ErrNotFound = errors.New("key not found") // ErrExists is returned if a key already exists ErrExists = errors.New("key already exists") // ErrReadOnly is returned if a write operation is attempted on a read-only // interface. Read-only interfaces are implemented as kvs.Store internally // for compatibility with other layers but exposing a kvs.StoreReader is // best practice in that case. ErrReadOnly = errors.New("write attempted on read only data source") )
Functions ¶
func TransformByteIndex ¶
TransformByteIndex splits the first hex byte off of a hash string and uses it as a directory name. Note that the filename inside this index directory has the first byte removed.
For example, the MD5 hash "4f41243847da693a4f356c0486114bc6" would be transformed to:
[]string{"4f", "41243847da693a4f356c0486114bc6"}
This transform is used if another function is not provided.
func TransformIdentity ¶
TransformIdentity is a transform function that returns the input key unchanged
Types ¶
type Store ¶
type Store interface { Exists(key string) (bool, error) Read(key string) ([]byte, error) ReadStream(key string) (io.ReadCloser, error) Write(key string, data []byte) error WriteStream(key string, reader io.Reader) error Remove(key string) error }
Store represents the atomic writing functions for a write-once KVS repository
func NewTranscoder ¶
func NewTranscoder(store Store, tcoder Transcoder, fileExt string) Store
NewTranscoder returns a TranscoderStore given a base Store, a Transcoder, and an optional file extension
type StoreReader ¶
type StoreReader interface { Read(key string) ([]byte, error) ReadStream(key string) (io.ReadCloser, error) Exists(key string) (bool, error) }
StoreReader represents the atomic reading functoins for a write-once KVS repository
type Transcoder ¶
type Transcoder interface { NewWriter(io.Writer) (io.WriteCloser, error) NewReader(io.ReadCloser) (io.ReadCloser, error) }
Transcoder represents an invertible pair of streaming encoder/decoder functions
type Writer ¶
type Writer interface { io.WriteCloser Abort() error }
Writer is a wrapper for a WriteCloser interface with an abort function