Documentation ¶
Index ¶
- type Store
- func (store *Store) Get(ctx context.Context, key string) ([]byte, error)
- func (store *Store) GetStream(ctx context.Context, key string) (io.ReadCloser, error)
- func (store *Store) Has(ctx context.Context, key string) (bool, error)
- func (store *Store) Peek(ctx context.Context, key string) ([]byte, io.Closer, error)
- func (store *Store) Put(ctx context.Context, key string, content []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
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 ¶
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 ¶
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.