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
- Variables
- func Dump(w io.Writer, r io.Reader) (err error)
- func DumpMap(r io.Reader, work func(Element) error) error
- func DumpToChan(c chan<- Element, r io.Reader) error
- func Make(w io.WriteSeeker, r io.Reader) (err error)
- func MakeFactory(w io.WriteSeeker) (adder AdderFunc, closer CloserFunc, err error)
- func MakeFromChan(w io.WriteSeeker, c <-chan Element) error
- type AdderFunc
- type Cdb
- type CdbWriter
- type CloserFunc
- type Element
Constants ¶
const MaxCdbSize = 1 << 32
MaxCdbSize is the maximum CDB size: 4Gb
Variables ¶
var BadFormatError = errors.New("bad format")
BadFormatError is the "bad format" error
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.
func DumpMap ¶
DumpMap calls work function for every element in the CDB if the function returns error, then quits with that error
func DumpToChan ¶
DumpToChan dumps elements into the given channel, does not close it!
func Make ¶
func Make(w io.WriteSeeker, r io.Reader) (err error)
Make reads cdb-formatted records from r and writes a cdb-format database to w. See the documentation for Dump for details on the input record format.
func MakeFactory ¶
func MakeFactory(w io.WriteSeeker) (adder AdderFunc, closer CloserFunc, err error)
MakeFactory creates CDB and returns an adder function which should be called with each Element, and a closer, which finalizes the CDB.
func MakeFromChan ¶
func MakeFromChan(w io.WriteSeeker, c <-chan Element) error
MakeFromChan makes CDB reading elements from the channel, does not close it!
Types ¶
type Cdb ¶
type Cdb struct {
// contains filtered or unexported fields
}
Cdb is the reader struct
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 ¶
func (c *Cdb) Find(key []byte) (rdata *io.SectionReader, err error)
Find returns the first data value for the given key as a SectionReader. Find is the same as FindStart followed by FindNext.
func (*Cdb) FindNext ¶
func (c *Cdb) FindNext(key []byte) (rdata *io.SectionReader, err error)
FindNext returns the next data value for the given key as a SectionReader. 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.