Exosphere.ATProto.CAR (Exosphere v0.2.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.

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.

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.