Fix progress bar
This commit is contained in:
@@ -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();
|
this.scheduleWork();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,4 +35,12 @@ export class PieceReassembler {
|
|||||||
}
|
}
|
||||||
return missing;
|
return missing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getBufferedBytes(): number {
|
||||||
|
let bytes = 0;
|
||||||
|
for (const data of this.blocks.values()) {
|
||||||
|
bytes += data.length;
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user