persist

package
v0.4.2-beta Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2015 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilEntry  = errors.New("entry does not exist")
	ErrNilBucket = errors.New("bucket does not exist")
)
View Source
var (
	ErrBadVersion = errors.New("incompatible version")
	ErrBadHeader  = errors.New("wrong header")
)
View Source
var NilDB nildb

NilDB is a db whose methods are no-ops. Calls to Block will return the zero value of types.Block. Calls to Height will return 0.

Functions

func Load added in v0.3.3

func Load(meta Metadata, data interface{}, r io.Reader) error

Load loads json data from a reader.

func LoadFile added in v0.3.3

func LoadFile(meta Metadata, data interface{}, filename string) error

LoadFile loads json data from a file.

func NewSafeFile added in v1.0.0

func NewSafeFile(filename string) (*safeFile, error)

func RandomSuffix added in v1.0.0

func RandomSuffix() string

RandomSuffix returns a 20 character base32 suffix for a filename. There are 100 bits of entropy, and a very low probability of colliding with existing files unintentionally.

func Save added in v0.3.3

func Save(meta Metadata, data interface{}, w io.Writer) error

Save saves json data to a writer.

func SaveFile added in v0.3.3

func SaveFile(meta Metadata, data interface{}, filename string) error

SaveFile saves json data to a file.

Types

type BoltDatabase added in v1.0.0

type BoltDatabase struct {
	*bolt.DB
	// contains filtered or unexported fields
}

func OpenDatabase added in v1.0.0

func OpenDatabase(meta Metadata, filename string) (*BoltDatabase, error)

openDatabase opens a database filename and checks metadata

func (*BoltDatabase) BucketSize

func (db *BoltDatabase) BucketSize(bucketName []byte) (uint64, error)

BucketSize returns the number of keys in a bucket.

func (*BoltDatabase) CloseDatabase

func (db *BoltDatabase) CloseDatabase() error

CloseDatabase saves the bolt database to a file, and updates metadata

func (*BoltDatabase) Exists

func (db *BoltDatabase) Exists(bucketName []byte, key []byte) (bool, error)

Exists checks for the existance of an item in the specified bucket

func (*BoltDatabase) GetFromBucket

func (db *BoltDatabase) GetFromBucket(bucketName string, key []byte) ([]byte, error)

GetFromBucket is a wrapper around a bolt database lookup. If the element does not exist, no error will be thrown, but the requested element will be nil.

type Metadata added in v0.3.3

type Metadata struct {
	Header, Version string
}

Metadata contains the header and version of the data being stored.

Jump to

Keyboard shortcuts

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