memstore

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 4 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	Bag map[string][]byte
}

Store is a simple in-memory storage. (It's little more than a map -- in fact, the map is exported, and you can poke it directly.)

Store conforms to the storage.ReadableStorage and storage.WritableStorage APIs. Additionally, it supports storage.PeekableStorage and storage.StreamingReadableStorage, because it can do so while provoking fewer copies.

If you want to use this store with streaming APIs, you can still do so by using the functions in the storage package, such as storage.GetStream and storage.PutStream, which will synthesize the correct behavior.

You can use this storage with a linking.LinkSystem easily, by using the LinkSystem.SetReadStorage and/or LinkSystem.SetWriteStorage methods.

There are no construction parameters for sharding functions nor escaping functions. Any keys are acceptable.

This storage is mostly expected to be used for testing and demos, and as an example of how you can implement and integrate your own storage systems. It does not provide persistence beyond memory.

func (*Store) Get

func (store *Store) Get(ctx context.Context, key string) ([]byte, error)

Get implements go-ipld-prime/storage.ReadableStorage.Get.

Note that this internally performs a defensive copy; use Peek for higher performance if you are certain you won't mutate the returned slice.

func (*Store) GetStream

func (store *Store) GetStream(ctx context.Context, key string) (io.ReadCloser, error)

GetStream implements go-ipld-prime/storage.StreamingReadableStorage.GetStream.

It's useful for this storage implementation to explicitly support this, because returning a reader gives us room to avoid needing a defensive copy.

func (*Store) Has

func (store *Store) Has(ctx context.Context, key string) (bool, error)

Has implements go-ipld-prime/storage.Storage.Has.

func (*Store) Peek

func (store *Store) Peek(ctx context.Context, key string) ([]byte, io.Closer, error)

Peek implements go-ipld-prime/storage.PeekableStorage.Peek.

func (*Store) Put

func (store *Store) Put(ctx context.Context, key string, content []byte) error

Put implements go-ipld-prime/storage.WritableStorage.Put.

Jump to

Keyboard shortcuts

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