Exosphere.ATProto.CAR (Exosphere v0.5.0)

Copy Markdown View Source

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:

  1. Header: varint-length-prefixed CBOR with {version, roots}
  2. 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

block_map()

@type block_map() :: %{required(Exosphere.ATProto.CID.t()) => term()}

Functions

decode(data)

@spec decode(binary()) :: {:ok, block_map()} | {:error, term()}

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).

decode_full(data)

@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.

get_block(blocks, cid)

@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.