kvs

package
v0.0.0-...-03333d7 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package kvs implements a write-once key-value store with different storage backends.

Index

Constants

This section is empty.

Variables

View Source
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

func TransformByteIndex(in string) []string

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

func TransformIdentity(in string) []string

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

Directories

Path Synopsis
compression
storage
fs
Package test contains integration tests for kvs modules.
Package test contains integration tests for kvs modules.

Jump to

Keyboard shortcuts

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