Fix progress bar

This commit is contained in:
Peter Stockings
2026-01-01 17:29:00 +11:00
parent cbe39e76a2
commit 28f011419c
2 changed files with 21 additions and 0 deletions

View File

@@ -232,6 +232,19 @@ export class TorrentSession {
}
}
// Calculate granular progress
const verifiedBytes = Array.from({ length: this.bitfield.totalPieces })
.filter((_, i) => this.bitfield!.has(i))
.length * this.pieceLength;
let bufferedBytes = 0;
for (const r of this.reassemblers.values()) {
bufferedBytes += r.getBufferedBytes();
}
const currentBytes = Math.min(this.totalSize, verifiedBytes + bufferedBytes); // Cap at total size
this.progress = Math.floor((currentBytes / this.totalSize) * 100);
this.scheduleWork();
}

View File

@@ -35,4 +35,12 @@ export class PieceReassembler {
}
return missing;
}
public getBufferedBytes(): number {
let bytes = 0;
for (const data of this.blocks.values()) {
bytes += data.length;
}
return bytes;
}
}