bufdb

package module
v0.0.0-...-3543f21 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2020 License: MIT Imports: 3 Imported by: 0

README

BufDB

GoDoc Software License Build Status Coverage Status

Usage

This package provides a persistence manager for github.com/djherbis/buffer Buffers.

import (
  "bytes"
  "io/ioutil"
  "os"
  "testing"

  "github.com/djherbis/buffer"

  bolt "go.etcd.io/bbolt"
)

func TestStore(t *testing.T) {
  db, err := bolt.Open("my.db", 0600, nil)
  if err != nil {
    t.Error(err.Error())
  }
  defer os.Remove("my.db")
  defer db.Close()

  store := NewBufferStore(db, []byte("buckets"))

  key := []byte("hello")
  input := []byte("hello world")

  b := buffer.NewPartition(buffer.NewFilePool(10, "."))
  b.Write(input)

  store.Put(key, b)
  buf, err := store.Pull(key)
  if err != nil {
    t.Error(err.Error())
  }

  data, err := ioutil.ReadAll(buf)

  if !bytes.Equal(data, input) {
    t.Errorf("expected %s, got %s", input, data)
  }

  store.Wipe()
}

Installation

go get github.com/djherbis/bufdb

Documentation

Overview

bufdb is used to persist buffer.Buffer's to a bolt.DB database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferPoolStore

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

func NewBufferPoolStore

func NewBufferPoolStore(db *bolt.DB, bucket []byte) *BufferPoolStore

func (*BufferPoolStore) DeleteAll

func (s *BufferPoolStore) DeleteAll() error

func (*BufferPoolStore) Pull

func (s *BufferPoolStore) Pull(key []byte) (p buffer.Pool, err error)

func (*BufferPoolStore) Put

func (s *BufferPoolStore) Put(key []byte, p buffer.Pool) error

type BufferStore

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

BufferStore manages buffer.Buffer persistance.

func NewBufferStore

func NewBufferStore(db *bolt.DB, bucket []byte) *BufferStore

NewBufferStore creates a new BufferStore, using the underlying bolt.DB "bucket" to persist buffers.

func (*BufferStore) DeleteAll

func (s *BufferStore) DeleteAll() error

DeleteAll will call Reset() on every buffer managed by this store, and then delete the buffer from the store.

func (*BufferStore) Pull

func (s *BufferStore) Pull(key []byte) (b buffer.Buffer, err error)

Pull will retrive (and removes) the buffer stored under "key". ErrNotFound indicates that the buffer was not found in the database, other errors indicate gob-decoding failures.

func (*BufferStore) Put

func (s *BufferStore) Put(key []byte, b buffer.Buffer) error

Put persists buffer.Buffer b, modifying b after Put will not affect the stored buffer. This will fail if the buffer is not gob-encodable.

Jump to

Keyboard shortcuts

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