Skip to main content

read_bundle_streaming

Function read_bundle_streaming 

Source
pub fn read_bundle_streaming<R, F>(
    src: R,
    restore: F,
) -> Result<Vec<MemberSpec>, BundleError>
where R: Read, F: FnMut(&MemberSpec, u64, &mut dyn Read) -> Result<(), BundleError>,
Expand description

Read a bundle from src in a SINGLE FORWARD PASS, handing each member to restore as it streams — never staging the whole bundle. Reads the MANIFEST first, then for each member calls restore(spec, size, body): body is a reader over the member’s bytes and size its declared length; the member’s SHA-256 is VERIFIED as body is consumed (and any bytes restore leaves unread are drained through the hasher), so a corrupt/truncated member is caught before the next.

Reads BOTH v2 bundles (ordered .brmeta sidecar + data pairs; size/SHA from the sidecar) and v1 bundles (size/SHA from the inline MANIFEST) — the compatibility path. For v2 the members arrive in the MANIFEST’s declared (restore) order, which is enforced; v1 members may arrive in any order and are matched by path (preserving v1 semantics). Returns the members restored, in the order they were handed to restore.