anacrolix / torrent

Full-featured BitTorrent client package and utilities
Mozilla Public License 2.0
5.39k stars 615 forks source link

file.BytesCompleted() always return 0 #851

Closed monkeyWie closed 11 months ago

monkeyWie commented 11 months ago

Firstly thanks for your great project. There have a problem that when I call file.BytesCompleted() to stat a special file speed it always return 0, bur call torrent.BytesCompleted() is fine, and it only seems to happen in torrent that piece length is longer.

This is my code:

fmt.Printf("file[%d] %d %d\n", i, torrent.Files()[i].BytesCompleted(), torrent.BytesCompleted())
// output
file[0]: 0 16384
file[0]: 0 65536
file[0]: 0 114688
file[0]: 0 245760
anacrolix commented 11 months ago

Sorry, it took a while for me to understand the problem. File.BytesCompleted is not including dirty chunks in the computation, but it does for Torrent.BytesCompleted.

anacrolix commented 11 months ago

One reason not to include dirty bytes in the computation is that they can fail piece checks, and so your download rate would appear to go backwards between successive calls. Is that okay?