rangesFor

fun rangesFor(piece: Int, offset: Int, length: Int): List<HttpRange>

Map a BitTorrent block request to the list of HTTP byte ranges that satisfy it. This is the pure, network-free core of fetchBlock. It delegates to WebSeedMapper, the testable port of the URL + Range computation in web_peer_connection::write_request together with file_storage::map_block.

The request covers length bytes starting at absolute torrent offset piece * pieceLength + offset. For a single-file torrent that is a single range against url. For a multi-file torrent the span is cut at every file boundary it crosses, producing one HttpRange per file (so a boundary-straddling block yields ≥2 ranges); the per-byte offsets in each range are file-relative, as HTTP Range demands.

Padding files (BEP-47) are included as ranges against their synthesised URL for completeness, but a real fetch would supply zeroes for them rather than hitting the network (libtorrent's handle_padfile); callers that fetch over HTTP should skip io.github.yuroyami.kitetorrent.torrent.FileEntry.isPadFile entries.

Throws

on an out-of-range or negative request.