Documentation ¶
Index ¶
- Constants
- Variables
- type Blockstore
- func (b *Blockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error)
- func (b *Blockstore) Close() error
- func (b *Blockstore) DeleteBlock(cid cid.Cid) error
- func (b *Blockstore) Get(cid cid.Cid) (blocks.Block, error)
- func (b *Blockstore) GetSize(cid cid.Cid) (int, error)
- func (b *Blockstore) Has(cid cid.Cid) (bool, error)
- func (b *Blockstore) HashOnRead(_ bool)
- func (b *Blockstore) PooledStorageKey(cid cid.Cid) (key []byte, pooled bool)
- func (b *Blockstore) Put(block blocks.Block) error
- func (b *Blockstore) PutMany(blocks []blocks.Block) error
- func (b *Blockstore) StorageKey(dst []byte, cid cid.Cid) []byte
- func (b *Blockstore) View(cid cid.Cid, fn func([]byte) error) error
- type Options
- type Suite
- func (s *Suite) RunTests(t *testing.T, prefix string)
- func (s *Suite) TestAllKeysRespectsContext(t *testing.T)
- func (s *Suite) TestAllKeysSimple(t *testing.T)
- func (s *Suite) TestCidv0v1(t *testing.T)
- func (s *Suite) TestDelete(t *testing.T)
- func (s *Suite) TestDoubleClose(t *testing.T)
- func (s *Suite) TestGetWhenKeyIsNil(t *testing.T)
- func (s *Suite) TestGetWhenKeyNotPresent(t *testing.T)
- func (s *Suite) TestHas(t *testing.T)
- func (s *Suite) TestPutMany(t *testing.T)
- func (s *Suite) TestPutThenGetBlock(t *testing.T)
- func (s *Suite) TestPutThenGetSizeBlock(t *testing.T)
- func (s *Suite) TestReopenPutGet(t *testing.T)
Constants ¶
const ( // FileIO is equivalent to badger/options.FileIO. FileIO = options.FileIO // MemoryMap is equivalent to badger/options.MemoryMap. MemoryMap = options.MemoryMap // LoadToRAM is equivalent to badger/options.LoadToRAM. LoadToRAM = options.LoadToRAM )
aliases to mask badger dependencies.
Variables ¶
var ( // ErrBlockstoreClosed is returned from blockstore operations after // the blockstore has been closed. ErrBlockstoreClosed = fmt.Errorf("badger blockstore closed") )
var ( // KeyPool is the buffer pool we use to compute storage keys. KeyPool *pool.BufferPool = pool.GlobalPool )
Functions ¶
This section is empty.
Types ¶
type Blockstore ¶
type Blockstore struct { DB *badger.DB // contains filtered or unexported fields }
Blockstore is a badger-backed IPLD blockstore.
NOTE: once Close() is called, methods will try their best to return ErrBlockstoreClosed. This will guaranteed to happen for all subsequent operation calls after Close() has returned, but it may not happen for operations in progress. Those are likely to fail with a different error.
func Open ¶
func Open(opts Options) (*Blockstore, error)
Open creates a new badger-backed blockstore, with the supplied options.
func (*Blockstore) AllKeysChan ¶
func (b *Blockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error)
AllKeysChan implements Blockstore.AllKeysChan.
func (*Blockstore) Close ¶
func (b *Blockstore) Close() error
Close closes the store. If the store has already been closed, this noops and returns an error, even if the first closure resulted in error.
func (*Blockstore) DeleteBlock ¶
func (b *Blockstore) DeleteBlock(cid cid.Cid) error
DeleteBlock implements Blockstore.DeleteBlock.
func (*Blockstore) Get ¶
func (b *Blockstore) Get(cid cid.Cid) (blocks.Block, error)
Get implements Blockstore.Get.
func (*Blockstore) GetSize ¶
func (b *Blockstore) GetSize(cid cid.Cid) (int, error)
GetSize implements Blockstore.GetSize.
func (*Blockstore) Has ¶
func (b *Blockstore) Has(cid cid.Cid) (bool, error)
Has implements Blockstore.Has.
func (*Blockstore) HashOnRead ¶
func (b *Blockstore) HashOnRead(_ bool)
HashOnRead implements Blockstore.HashOnRead. It is not supported by this blockstore.
func (*Blockstore) PooledStorageKey ¶
func (b *Blockstore) PooledStorageKey(cid cid.Cid) (key []byte, pooled bool)
PooledStorageKey returns the storage key under which this CID is stored.
The key is: prefix + base32_no_padding(cid.Hash)
This method may return pooled byte slice, which MUST be returned to the KeyPool if pooled=true, or a leak will occur.
func (*Blockstore) Put ¶
func (b *Blockstore) Put(block blocks.Block) error
Put implements Blockstore.Put.
func (*Blockstore) PutMany ¶
func (b *Blockstore) PutMany(blocks []blocks.Block) error
PutMany implements Blockstore.PutMany.
func (*Blockstore) StorageKey ¶
func (b *Blockstore) StorageKey(dst []byte, cid cid.Cid) []byte
Storage acts like PooledStorageKey, but attempts to write the storage key into the provided slice. If the slice capacity is insufficient, it allocates a new byte slice with enough capacity to accommodate the result. This method returns the resulting slice.
type Options ¶
type Options struct { badger.Options // Prefix is an optional prefix to prepend to keys. Default: "". Prefix string }
Options embeds the badger options themselves, and augments them with blockstore-specific options.
func DefaultOptions ¶
type Suite ¶
type Suite struct { NewBlockstore func(tb testing.TB) (bs blockstore.Blockstore, path string) OpenBlockstore func(tb testing.TB, path string) (bs blockstore.Blockstore, err error) }
TODO: move this to go-ipfs-blockstore.