Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add comments describing methods & interfaces #71

Merged
merged 1 commit into from
Jan 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,33 @@ import (
cbg "github.com/whyrusleeping/cbor-gen"
)

// IpldStore wraps a Blockstore and provides an interface for storing and retrieving CBOR encoded data.
type IpldStore interface {
Get(ctx context.Context, c cid.Cid, out interface{}) error
Put(ctx context.Context, v interface{}) (cid.Cid, error)
}

// IpldBlockstore defines a subset of the go-ipfs-blockstore Blockstore interface providing methods
// for storing and retrieving block-centered data.
type IpldBlockstore interface {
Get(cid.Cid) (block.Block, error)
Put(block.Block) error
}

// BasicIpldStore wraps and IpldBlockstore and implements the IpldStore interface.
type BasicIpldStore struct {
Blocks IpldBlockstore
Atlas *atlas.Atlas
}

var _ IpldStore = &BasicIpldStore{}

// NewCborStore returns an IpldStore implementation backed by the provided IpldBlockstore.
func NewCborStore(bs IpldBlockstore) *BasicIpldStore {
return &BasicIpldStore{Blocks: bs}
}

// Get reads and unmarshals the content at `c` into `out`.
func (s *BasicIpldStore) Get(ctx context.Context, c cid.Cid, out interface{}) error {
blk, err := s.Blocks.Get(c)
if err != nil {
Expand All @@ -59,6 +65,7 @@ type cidProvider interface {
Cid() cid.Cid
}

// Put marshals and writes content `v` to the backing blockstore returning its CID.
func (s *BasicIpldStore) Put(ctx context.Context, v interface{}) (cid.Cid, error) {
mhType := uint64(mh.BLAKE2B_MIN + 31)
mhLen := -1
Expand Down