cdb

package module
v0.0.0-...-6a418fa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2016 License: MIT Imports: 12 Imported by: 3

README

go-cdb

Go interface to Constant Databases (CDB)

A pure Go reader & writer of the Constant Database format. See http://cr.yp.to/cdb.html to read more about constant databases.

This was originally a fork of https://github.com/jbarham/go-cdb however improvements were added to make the Reader threadsafe and support memory mapping the CDB files.

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

View Source
var BadFormatError = errors.New("bad format")

Functions

func Dump

func Dump(w io.Writer, r io.Reader) (err error)

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 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.

Types

type Cdb

type Cdb struct {
	// contains filtered or unexported fields
}

func New

func New(r io.ReaderAt) *Cdb

New creates a new Cdb from the given ReaderAt, which should be a cdb format database.

func Open

func Open(name string) (*Cdb, error)

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) Close

func (c *Cdb) Close() (err error)

Close closes the cdb for any further reads.

func (*Cdb) Data

func (c *Cdb) Data(key []byte, context *Context) ([]byte, error)

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, context *Context) ([]byte, error)

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

func (c *Cdb) FindNext(key []byte, context *Context) ([]byte, error)

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.

func (*Cdb) FindStart

func (c *Cdb) FindStart(context *Context)

FindStart resets the cdb to search for the first record under a new key.

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.

func NewReader

func NewReader(fileName string) (Reader, error)

NewReader returns a constant database reader that uses go-cdb as its implementation.

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.

func NewWriter

func NewWriter(fileName string) (Writer, error)

NewWriter returns a constant database writer that uses go-cdb as its implementation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL