Locate a DataItem by byte range inside an ANS-104 bundle

An Arweave binary bundle stores a table of item lengths and IDs ahead of its bodies. The second item does not begin immediately after the first length entry.

Compute offsets from the header end

Read the item count from the 32-byte prefix, validate the table size, then read its 64-byte entries. In the example, both bodies start after byte 159. The first item occupies 1,100 bytes, so the second starts at offset 1,260. Use an integer representation large enough for the encoded sizes and bounds-check before allocating.

item count = 2
header bytes = 32 + 2 × 64 = 160
item lengths = 1100, 1350
body ranges = [160,1260), [1260,2610)

Validate the extracted item

A half-open end offset is convenient in memory. If an HTTP server expects an inclusive range, subtract one from the end. Check the item's ID and signature against its body before indexing it. A plausible length table establishes byte boundaries but says nothing about the authenticity of its contents.

Sources