pub fn read(bytes: &[u8]) -> Result<Car, CarError>Expand description
Reads a CARv1 file.
Every block is hashed and checked against the CID it is filed under. That is not an optional strictness: a CAR file is a claim that these bytes are those names, and a reader that skips the check turns a corrupted download into a repository that verifies against itself and against nothing else. The cost is one sha-256 per block, which is the same hash the sender paid to name it.
The version field is checked to be 1. There is no CARv2 support here and the failure for one is a header that says so rather than a parse that wanders into the index.
use didbot_data::Cid;
use didbot_repo::car;
let block = b"not a real block".to_vec();
let cid = Cid::of_raw(&block);
let bytes = car::write(&cid, [(cid.clone(), block.clone())]);
let read = car::read(&bytes).expect("a car this crate wrote");
assert_eq!(read.roots, vec![cid.clone()]);
assert_eq!(read.blocks[&cid], block);