Documentation
¶
Overview ¶
Package cdb reads and writes cdb ("constant database") files.
See the original cdb specification and C implementation by D. J. Bernstein at http://cr.yp.to/cdb.html.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var BadFormatError = errors.New("bad format")
Functions ¶
func Dump ¶
Dump reads the cdb-formatted data in r and dumps it as a series of formatted records (+klen,dlen:key->data\n) and a final newline to w. The output of Dump is suitable as input to Make. See http://cr.yp.to/cdb/cdbmake.html for details on the record format.
Types ¶
type Cdb ¶
type Cdb struct {
// contains filtered or unexported fields
}
func Open ¶
Open opens the named file read-only and returns a new Cdb object. The file should exist and be a cdb-format database file.
func (*Cdb) Data ¶
Data returns the first data value for the given key. If no such record exists, it returns EOF.
func (*Cdb) Find ¶
Find returns the first data value for the given key as a byte slice. Find is the same as FindStart followed by FindNext.
func (*Cdb) FindNext ¶
FindNext returns the next data value for the given key as a byte slice. If there are no more records for the given key, it returns EOF. FindNext acts as an iterator: The iteration should be initialized by calling FindStart and all subsequent calls to FindNext should use the same key value.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func NewContext ¶
func NewContext() *Context
NewContext returns a new context to be used in CDB calls.
type Reader ¶
type Reader interface { // Preload preloads the database. Preload() // First returns the first value associated with the given key and tag. First(key []byte, tag uint8) ([]byte, bool) // Exists returns true if key is found. False otherwise. Exists(key []byte, tag uint8) bool // Close closes the database. Close() }
Reader is the interface to be used by constant database readers. Its methods are the same present in mcdb.Reader so that can also satisfy this interface.
type Writer ¶
type Writer interface { // Put adds a new key/value pair associated with the given tag, Put(key, value []byte, tag uint8) error // Close closes the constant database, flushing all data to disk. Close() error }
Writer is the interface to be used by constant database writers. Its methods are the same present in mcdb.Writer so that can also satisfy this interface.