ipld / ipld/go-car

carv2/ReadWriteBlockstore: support deferred root CIDs

Open
#196 5 comments 0 reactions 0 assignees View on GitHub
P2
Dominant language
Go
Stars
175
Forks
54
Avg merge
6d 5h
Merged PRs (30d)
4

Description

`blockstore.OpenReadWrite` requires providing the root CIDs when creating a new blockstore. This design inhibits the ability to use a CARv2 blockstore as the target of a streaming merkle DAG formation like UnixFS, as the root CID is not known beforehand.

We could work around this situation by supplying a placeholder root CID, and once the blockstore is finalized, we could go back and replace those bytes in the header.

Unfortunately, the library doesn't provide APIs to do that safely and without making assumptions about the underlying format, or breaking abstractions.

Some ideas:

1. Allow `blockstore.OpenReadWrite` to take a `[]struct{cid.Builder, func() (cid.Cid, error)}`.
- Use the `cid.Builder`s to compute the length of each CID, and preallocate those bytes in the header.
- On Finalize, call each function to get the actual CID to replace it in the header.
2. Simpler: allow the user to specify a number of bytes to preallocate, and provide primitives to update a CAR header.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.