container: add cbor serialisation

This commit is contained in:
Michael Muré
2024-09-19 21:26:42 +02:00
parent df9beadf9c
commit 346efbd31d
5 changed files with 66 additions and 8 deletions

View File

@@ -29,7 +29,9 @@ type carBlock struct {
data []byte
}
// writeCar writes a CARv1 file with no roots, containing the blocks from the iterator.
// writeCar writes a CARv1 file containing the blocks from the iterator.
// If no roots are provided, a single EmptyCid is used as root to make the file
// spec compliant.
func writeCar(w io.Writer, roots []cid.Cid, blocks iter.Seq[carBlock]) error {
if len(roots) == 0 {
roots = []cid.Cid{EmptyCid}