Bounded CARv1 archive streaming, verification and offset indexing for MoonBit.
Dependencies
git clone https://github.com/CaptainK-65/moon-car.git
cd moon-car
moon update
moon check --target all --deny-warn
moon test --target all
moon build --target all
moon run examples/pack
moon run examples/stream
moon run examples/lookup
moon run cmd/mooncar --target native -- verify fixtures/carv1-basic.carlet cid = @cid.cid_from_content(
@cid.RAW_CODEC, @cid.Sha2_256, b"hello",
@cid.sha2_provider(), @cid.Limits::default(),
).unwrap()
let bytes = @car.encode(@car.Header::new([cid]), [@car.Block::new(cid, b"hello")])
let archive = @car.Archive::decode(bytes)
archive.verify(require_roots=true)
let payload = archive.get(cid).data()| Use case | Processing | Runnable example |
|---|---|---|
| Distribution | Hash objects, write archive, read and verify it | moon run examples/pack |
| Transport snapshot | Feed seven-byte chunks, consume and verify events, finish at EOF | moon run examples/stream |
| Object lookup | Scan once, index full CID bytes, locate and verify a payload | moon run examples/lookup |
moon run cmd/mooncar --target native -- pack bundle.car README.md
moon run cmd/mooncar --target native -- inspect bundle.car
moon run cmd/mooncar --target native -- verify bundle.car
moon run cmd/mooncar --target native -- get bundle.car CID extracted.bin
moon run cmd/mooncar --target native -- rewrite bundle.car rewritten.carpub(all) suberror CarError {
InvalidHeader(String)
InvalidCid(String)
InvalidVarint(Int)
LimitExceeded(String, UInt64, UInt64)
Truncated(Int)
InvalidState(String)
Integrity(Int, String)
MissingRoot(String)
NotFound
} derive(Debug)fn Archive::verify(self : Archive, provider? : HashProvider, require_roots? : Bool) -> Unit raise CarErrorpub struct Limits {
max_header : Int
max_block : Int
max_roots : Int
max_blocks : Int
max_archive : Int
}pub(all) struct Location {
section_offset : Int
data_offset : Int
data_length : Int
section_length : Int
} derive(Debug)Install
Download zipBounded CARv1 archive streaming, verification and offset indexing for MoonBit.
Dependencies