go-car
go-car copied to clipboard
carv2/ReadWriteBlockstore: support deferred root CIDs
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:
- 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.
- Use the
- Simpler: allow the user to specify a number of bytes to preallocate, and provide primitives to update a CAR header.