Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Compression ¶
type Compression interface { Compress(dst io.Writer, src io.Reader) error Decompress(dst io.Writer, src io.Reader) error }
Compression defines an interface that Diskv uses to implement compression of data. You may define these methods on your own type, or use one of the NewCompression helpers.
func NewGzipCompression ¶
func NewGzipCompression() Compression
func NewGzipCompressionLevel ¶
func NewGzipCompressionLevel(level int) Compression
func NewZlibCompression ¶
func NewZlibCompression() Compression
func NewZlibCompressionLevel ¶
func NewZlibCompressionLevel(level int) Compression
func NewZlibCompressionLevelDict ¶
func NewZlibCompressionLevelDict(level int, dict []byte) Compression
type Diskv ¶
Diskv implements the Diskv interface. You shouldn't construct Diskv structures directly; instead, use the New constructor.
func New ¶
New returns an initialized Diskv structure, ready to use. If the path identified by baseDir already contains data, it will be accessible, but not yet cached.
func (*Diskv) EraseAll ¶
EraseAll will delete all of the data from the store, both in the cache and on the disk. Note that EraseAll doesn't distinguish diskv-related data from non-diskv-related data. Care should be taken to always specify a diskv base directory that is exclusively for diskv data.
func (*Diskv) Keys ¶
Keys returns a channel that will yield every key accessible by the store in undefined order.
func (*Diskv) Read ¶
Read reads the key and returns the value. If the key is available in the cache, Read won't touch the disk. If the key is not in the cache, Read will have the side-effect of lazily caching the value.
type GenericCompression ¶
type GenericCompression struct {
// contains filtered or unexported fields
}
A GenericCompression implements Diskv's Compression interface. Users must supply it with two functions: a WriterFunc, which wraps an io.Writer with a compression layer, and a ReaderFunc, which wraps an io.Reader with a decompression layer.
func NewCompression ¶
func NewCompression(wf WriterFunc, rf ReaderFunc) *GenericCompression
NewCompression returns a GenericCompression from the passed Writer and Reader functions, which you may supply directly.
You may also use one of the NewCompression helpers, which automatically provide Writer and Reader functions for some of the stdlib compression algorithms.
func (*GenericCompression) Decompress ¶
type Index ¶
type Index interface { Initialize(less LessFunction, keys <-chan string) Insert(key string) Delete(key string) Keys(from string, n int) <-chan string }
Index is a generic interface for things that can provide an ordered list of keys.
type LLRBIndex ¶
LLRBIndex is an implementation of the Index interface using Petar Maymounkov's LLRB tree.
func (*LLRBIndex) Initialize ¶
func (i *LLRBIndex) Initialize(less LessFunction, keys <-chan string)
Initialize populates the LLRB tree with data from the keys channel, according to the passed less function. It's destructive to the LLRBIndex.
func (*LLRBIndex) Keys ¶
Keys yields a maximum of n keys on the returned channel, in order. It's designed to effect a simple "pagniation" of keys.
If the passed 'from' key is empty, Keys will return the first n keys. If the passed 'from' key is non-empty, the first key in the returned slice will be the key that immediately follows the passed key, in key order.
type LessFunction ¶
LessFunction is used to initialize an Index of keys in a specific order.
type Options ¶
type Options struct { BasePath string Transform TransformFunction CacheSizeMax uint64 // bytes PathPerm os.FileMode FilePerm os.FileMode Index Index IndexLess LessFunction Compression Compression }
Options define a set of properties that dictate Diskv behavior. All values are optional.
type ReaderFunc ¶
type ReaderFunc func(r io.Reader) (io.ReadCloser, error)
ReaderFunc yields an io.ReadCloser which should perform decompression from the passed io.Reader.
type TransformFunction ¶
A TransformFunc transforms a key into a slice of strings, with each element in the slice representing a directory in the file path where the key's entry will eventually be stored.
For example, if TransformFunc transforms "abcdef" to ["ab", "cde", "f"], the final location of the data file will be <basedir>/ab/cde/f/abcdef
type WriterFunc ¶
type WriterFunc func(w io.Writer) (io.WriteCloser, error)
WriterFunc yields an io.WriteCloser which should perform compression into the passed io.Writer.