CAR (Content Addressable aRchive) file parser.
CAR files are used in Exosphere.ATProto to bundle multiple CBOR blocks together, typically containing record data and MST (Merkle Search Tree) nodes.
Format
A CAR file consists of:
- Header: varint-length-prefixed CBOR with
{version, roots} - Blocks: repeated
<varint-length><CID><data>entries
Usage
# Parse CAR blocks from firehose
{:ok, blocks} = Exosphere.ATProto.CAR.decode(car_binary)
# Get a specific record by CID
record = Exosphere.ATProto.CAR.get_block(blocks, cid)
Summary
Functions
Decode a CAR file into a map of CID → decoded data.
Decode a CAR file into its header roots and block map.
Get a block by CID from the parsed blocks map.
Types
@type block_map() :: %{required(Exosphere.ATProto.CID.t()) => term()}
Functions
Decode a CAR file into a map of CID → decoded data.
Returns {:ok, %{cid => data}} on success. The header's roots are
discarded; use decode_full/1 when you need them (e.g. to locate a
repository's root commit for verification).
@spec decode_full(binary()) :: {:ok, %{roots: [Exosphere.ATProto.CID.t()], blocks: block_map()}} | {:error, term()}
Decode a CAR file into its header roots and block map.
Returns {:ok, %{roots: [%CID{}, ...], blocks: %{cid => data}}}. The roots
come from the CAR header (CID links decoded via Exosphere.ATProto.CBOR.transform_links/1);
for atproto repository archives the single root is the CID of the top commit
block, which is itself present in blocks.
@spec get_block(block_map(), Exosphere.ATProto.CID.t() | String.t()) :: term() | nil
Get a block by CID from the parsed blocks map.
Returns the decoded CBOR data if found.