Skip to main content

align_range

Function align_range 

Source
pub fn align_range(
    byte_offset: u64,
    byte_len: u64,
    blob_size: u64,
) -> Result<AlignedRange, RangeVerifyError>
Expand description

Compute the chunk-group-aligned fetch span for a [byte_offset, +byte_len) request against a blob_size-byte blob. byte_len == 0 means “to end”.

The empty (0-byte) blob is addressable only as the whole blob — (0, 0) — and aligns to an empty AlignedRange (fetch_start == fetch_end == 0, empty chunk_ranges, zero wire_len). This preserves the pre-bao empty-bytes delivery on the bao path (#1054); the empty stream is still proven against the empty root blake3::hash(&[]) by the receiver, never accepted for an arbitrary root.

§Errors

RangeVerifyError::RangeOutOfBounds if the offset is past the blob end, or the explicit end overflows / exceeds the blob size. For a 0-byte blob, any positive offset or explicit positive length is out of bounds. Use align_range_clamped when an end past the blob should be served up to the blob’s end instead of refused.