Expand description
CAR (Content Addressable aRchive) format support.
This module provides utilities for reading and writing CAR files, which are used to package and transfer IPLD blocks in the IPFS ecosystem.
CAR (CARv1) format structure:
- Header: CBOR-encoded with version and root CIDs
- Blocks: Sequence of length-prefixed blocks (varint length + CID + data)
§Examples
use ipfrs_core::{Block, car::{CarWriter, CarReader}};
use bytes::Bytes;
// Create some blocks
let block1 = Block::new(Bytes::from_static(b"Hello, CAR!")).unwrap();
let block2 = Block::new(Bytes::from_static(b"CAR format test")).unwrap();
// Write to CAR format
let mut car_data = Vec::new();
let mut writer = CarWriter::new(&mut car_data, vec![*block1.cid()]).unwrap();
writer.write_block(&block1).unwrap();
writer.write_block(&block2).unwrap();
writer.finish().unwrap();
// Read from CAR format
let reader = CarReader::new(&car_data[..]).unwrap();
let roots = reader.roots();
assert_eq!(roots.len(), 1);
assert_eq!(roots[0], *block1.cid());Structs§
- CarCompression
Stats - Compression statistics for CAR operations.
- CarHeader
- CAR file header containing version and root CIDs.
- CarReader
- Read blocks from CAR format.
- CarWriter
- Write blocks to CAR format.
- CarWriter
Builder - Builder for creating a CarWriter with optional compression.