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 ¶
- Variables
- func Dump(w io.Writer, r io.Reader) (err error)
- func Make(w io.WriteSeeker, r io.Reader) (err error)
- type Cdb
- func (c *Cdb) Bytes(key []byte) ([]byte, error)
- func (c *Cdb) Close() (err error)
- func (c *Cdb) Exists(key []byte) (bool, error)
- func (c *Cdb) ForEachBytes(onRecordFn func(key, val []byte) error) error
- func (c *Cdb) ForEachReader(onRecordFn func(keyReader, valReader *io.SectionReader) error) error
- func (c *Cdb) Iterate(key []byte) *CdbIterator
- func (c *Cdb) Reader(key []byte) (*io.SectionReader, error)
- type CdbIterator
- type Writer
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) Bytes ¶
Bytes returns the first value for this key as a []byte. Returns EOF when there is no value.
Threadsafe.
func (*Cdb) ForEachBytes ¶
ForEachBytes calls onRecordFn for every key-val pair in the database.
The byte slices are only valid for the length of a call to onRecordFn.
If onRecordFn returns an error, iteration will stop and the error will be returned.
Threadsafe.
func (*Cdb) ForEachReader ¶
func (c *Cdb) ForEachReader(onRecordFn func(keyReader, valReader *io.SectionReader) error) error
ForEachReader calls onRecordFn for every key-val pair in the database.
If onRecordFn returns an error, iteration will stop and the error will be returned.
Threadsafe.
func (*Cdb) Iterate ¶
func (c *Cdb) Iterate(key []byte) *CdbIterator
Iterate returns an iterator that can be used to access all of the values for a key. Always returns a non-nil value, even if the key has no values.
Because the iterator keeps a reference to the byte slice, it shouldn't be modified until the iterator is no longer in use.
Threadsafe.
type CdbIterator ¶
type CdbIterator struct {
// contains filtered or unexported fields
}
func (*CdbIterator) NextBytes ¶
func (iter *CdbIterator) NextBytes() ([]byte, error)
NextBytes returns the next value for this iterator as a []byte. Returns EOF when there are no values left.
Not threadsafe.
func (*CdbIterator) NextReader ¶
func (iter *CdbIterator) NextReader() (*io.SectionReader, error)
NextReader returns the next value for this iterator as an io.SectionReader. Returns EOF when there are no values left.
Not threadsafe.