How does aria2 manage segmented file selection?

The command-line download utility aria2 optimizes file transfers by breaking target files into multiple segments and fetching them concurrently across different connections or protocols. When executing segmented downloads, aria2 primarily uses a sequential piece selection strategy by default for standard HTTP(S) and FTP downloads, while employing a rarest-first algorithm for BitTorrent distributions. This segmented approach allows the client to maximize available network bandwidth, efficiently manage connection states, and smoothly resume interrupted transfers.

Core Allocation and the Split Strategy

When a download is initiated, aria2 references the user-defined --split parameter to determine how many connections to open for a single file. Based on this number and the total file size, the engine divides the payload into logical segments. However, fragmentation is protected by the --min-split-size setting, which ensures that a file is not split into excessively small chunks if the remaining size per connection falls below the defined threshold. This keeps the protocol overhead to a minimum.

HTTP and FTP Selection Mechanics

For traditional client-server connections, aria2 requests explicit byte ranges from the hosting server.

BitTorrent and P2P Piece Selection

When handling BitTorrent or Metalink files with piece hashes, aria2 shifts its methodology to adapt to distributed networks. Rather than downloading linearly, it defaults to a rarest-first selection strategy.

By analyzing the bitfields of connected peers, aria2 identifies which file pieces are least common in the swarm and prioritizes downloading those first. This protects the health of the peer-to-peer network and prevents the download from stalling on rare segments near completion. If the download is configured for streaming, aria2 can be toggled back to a sequential approach to prioritize the immediate availability of the file’s front end.

The Role of the Control File

Every segmented download is anchored by a companion .aria2 binary control file. This control file acts as a local map, tracking the exact byte offsets, completed ranges, and pending pieces. If a connection drops or the process terminates, aria2 reads this control file upon restart, dynamically evaluates which segments are still missing, and reapplies its piece selection rules to resume the download exactly where it left off.