I want to get the size of a file that is being downloaded. Since the file is preallocated, using du -sd
just returns its final, full size. I want to know how much has been downloaded, so I don't want those trailing zero bytes to count. How do I get this size?
This should be possible, since aria2c
can easily resume its stopped downloads, and it doesn't seem to store the downloaded length in its control (session) files. I have written a script to read total_length
from .aria2
control files. This is the total length though, not downloaded length. You can easily use that script and the technical specs to get any other property aria2 stores.
Update from comments:
As ilkkachu was hinting, BITFIELD in the .aria2 file seems to actually
be a map: each bit corresponds to a file chunk, 1 meaning "downloaded"
(0 meaning "not downloaded"). BITFIELD LENGTH gives you the number of
chunks (and the chunk size is likely just that of the file divided by
the chunk number). I'm pretty sure the download progress is given by
the ratio of 1s over the number of chunks in BITFIELD. Unfortunately,
AFAICT, the .aria2 file seems to be updated after some delay, or as
soon as the download is interrupted.
Best Answer
Considering just the issue of finding out how far along
aria2
is on a download, there's a few choices.As discussed in the comments, the information is in a bitmap in the control file (
filename.aria2
). It's documented in https://aria2.github.io/manual/en/html/technical-notes.html . Having a bitmap doesn't make much sense for an HTTP download, which goes linearly from the start, but I suppose it would make more sense for a BitTorrent download or such.Here's a hex dump of a control file for a particular download with the important fields marked (
od -tx1 file.aria2
):Counting the set bits in the bitmap, that particular download was interrupted after at least 191 pieces of 1 MiB (200278016 bytes) were downloaded, which pretty much matches the resulting file size I got, 201098200 bytes. (The actual file was bigger by just less then an MiB, the records for in-flight pieces in the control file might mark that, but I didn't care. I didn't have pre-allocation on, just so that I could cross check with the size on the filesystem.)
By default
aria2c
saves the control file every 60 seconds, but we can use--auto-save-interval=<secs>
to change that:Alternatively, I suppose you could use
aria2c --log=<logfile>
and fish the download progress out of the log. Though it seems the progress is only shown write cache entries inDEBUG
level messages, and with those enabled, the log is rather verbose.Also, you could use
--summary-interval=1
to print some progress output tostdout
, possibly redirected to some log file (and perhaps with--show-console-readout=false
to hide the live readout). Though it only seems to give rounded figures: