const defaultBasePath … const defaultFilePerm … const defaultPathPerm … var defaultTransform … var errCanceled … var errEmptyKey … var errBadKey … var errImportDirectory … type TransformFunction … type Options … type Diskv … // 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 New(o Options) *Diskv { … } // Write synchronously writes the key-value pair to disk, making it immediately // available for reads. Write relies on the filesystem to perform an eventual // sync to physical media. If you need stronger guarantees, see WriteStream. func (d *Diskv) Write(key string, val []byte) error { … } // WriteStream writes the data represented by the io.Reader to the disk, under // the provided key. If sync is true, WriteStream performs an explicit sync on // the file as soon as it's written. // // bytes.Buffer provides io.Reader semantics for basic data types. func (d *Diskv) WriteStream(key string, r io.Reader, sync bool) error { … } // createKeyFileWithLock either creates the key file directly, or // creates a temporary file in TempDir if it is set. func (d *Diskv) createKeyFileWithLock(key string) (*os.File, error) { … } // writeStream does no input validation checking. func (d *Diskv) writeStreamWithLock(key string, r io.Reader, sync bool) error { … } // Import imports the source file into diskv under the destination key. If the // destination key already exists, it's overwritten. If move is true, the // source file is removed after a successful import. func (d *Diskv) Import(srcFilename, dstKey string, move bool) (err error) { … } // 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. func (d *Diskv) Read(key string) ([]byte, error) { … } // ReadStream reads the key and returns the value (data) as an io.ReadCloser. // If the value is cached from a previous read, and direct is false, // ReadStream will use the cached value. Otherwise, it will return a handle to // the file on disk, and cache the data on read. // // If direct is true, ReadStream will lazily delete any cached value for the // key, and return a direct handle to the file on disk. // // If compression is enabled, ReadStream taps into the io.Reader stream prior // to decompression, and caches the compressed data. func (d *Diskv) ReadStream(key string, direct bool) (io.ReadCloser, error) { … } // read ignores the cache, and returns an io.ReadCloser representing the // decompressed data for the given key, streamed from the disk. Clients should // acquire a read lock on the Diskv and check the cache themselves before // calling read. func (d *Diskv) readWithRLock(key string) (io.ReadCloser, error) { … } type closingReader … func (cr closingReader) Read(p []byte) (int, error) { … } type siphon … // newSiphon constructs a siphoning reader that represents the passed file. // When a successful series of reads ends in an EOF, the siphon will write // the buffered data to Diskv's cache under the given key. func newSiphon(f *os.File, d *Diskv, key string) io.Reader { … } // Read implements the io.Reader interface for siphon. func (s *siphon) Read(p []byte) (int, error) { … } // Erase synchronously erases the given key from the disk and the cache. func (d *Diskv) Erase(key string) error { … } // 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 (d *Diskv) EraseAll() error { … } // Has returns true if the given key exists. func (d *Diskv) Has(key string) bool { … } // Keys returns a channel that will yield every key accessible by the store, // in undefined order. If a cancel channel is provided, closing it will // terminate and close the keys channel. func (d *Diskv) Keys(cancel <-chan struct{ … } // KeysPrefix returns a channel that will yield every key accessible by the // store with the given prefix, in undefined order. If a cancel channel is // provided, closing it will terminate and close the keys channel. If the // provided prefix is the empty string, all keys will be yielded. func (d *Diskv) KeysPrefix(prefix string, cancel <-chan struct{ … } // walker returns a function which satisfies the filepath.WalkFunc interface. // It sends every non-directory file entry down the channel c. func walker(c chan<- string, prefix string, cancel <-chan struct{ … } // pathFor returns the absolute path for location on the filesystem where the // data for the given key will be stored. func (d *Diskv) pathFor(key string) string { … } // ensurePathWithLock is a helper function that generates all necessary // directories on the filesystem for the given key. func (d *Diskv) ensurePathWithLock(key string) error { … } // completeFilename returns the absolute path to the file for the given key. func (d *Diskv) completeFilename(key string) string { … } // cacheWithLock attempts to cache the given key-value pair in the store's // cache. It can fail if the value is larger than the cache's maximum size. func (d *Diskv) cacheWithLock(key string, val []byte) error { … } // cacheWithoutLock acquires the store's (write) mutex and calls cacheWithLock. func (d *Diskv) cacheWithoutLock(key string, val []byte) error { … } func (d *Diskv) bustCacheWithLock(key string) { … } func (d *Diskv) uncacheWithLock(key string, sz uint64) { … } // pruneDirsWithLock deletes empty directories in the path walk leading to the // key k. Typically this function is called after an Erase is made. func (d *Diskv) pruneDirsWithLock(key string) error { … } // ensureCacheSpaceWithLock deletes entries from the cache in arbitrary order // until the cache has at least valueSize bytes available. func (d *Diskv) ensureCacheSpaceWithLock(valueSize uint64) error { … } type nopWriteCloser … func (wc *nopWriteCloser) Write(p []byte) (int, error) { … } func (wc *nopWriteCloser) Close() error { … }