Documentation ¶
Overview ¶
Package cdb64 provides a native implementation of cdb, a fast constant key/value database, but without the 4GB size limitation.
For more information on cdb, see the original design doc at http://cr.yp.to/cdb.html.
This is based on https://github.com/chrislusf/cdb64 which in itself is based on https://github.com/colinmarc/cdb.
Example ¶
package main import ( "fmt" "log" "github.com/bsm/cdb64" ) func main() { w, err := cdb64.Create("/tmp/cdb64-example.cdb") if err != nil { log.Fatalln(err) } defer w.Close() // Write some key/value pairs. _ = w.Put([]byte("Alice"), []byte("Hoax")) _ = w.Put([]byte("Bob"), []byte("Hope")) _ = w.Put([]byte("Charlie"), []byte("Horse")) // Freeze and re-open it for reading. db, err := w.Freeze() if err != nil { log.Fatalln(err) } defer db.Close() // Fetch a value. v, err := db.Get([]byte("Alice")) if err != nil { log.Fatalln(err) } fmt.Print(string(v)) }
Output: Hoax
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Batch ¶ added in v0.7.0
type Batch struct {
// contains filtered or unexported fields
}
Batch instances allow to query the Reader more efficiently with a sequence of Get requests. Unlike Readers, Batches are not thread-safe and must not be shared across goroutines.
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator represents a sequential iterator over a CDB database.
func (*Iterator) Key ¶
Key returns the current key, which is valid until a subsequent call to Next(). You must copy they key if you plan to use it beyond this point.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader represents a thread-safe CDB database reader. To create a database, use Writer.
func (*Reader) Batch ¶ added in v0.7.0
Batch creates a new batch operator. Please note that Batch instances are not thread-safe and must not be shared across goroutines.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer provides an API for creating a CDB database record by record.
Close (or Freeze) must be called to finalize the database, or the resulting file will be invalid. Any errors during writing or finalizing are unrecoverable.
func Create ¶
Create opens a CDB database at the given path. If the file exists, it will be overwritten.
func (*Writer) Close ¶
Close finalizes the database, then closes it to further writes.
Close or Freeze must be called to finalize the database, or the resulting file will be invalid.