]> Sergey Matveev's repositories - btrtrc.git/blobdiff - file.go
Use rejiggered missinggo bitmap
[btrtrc.git] / file.go
diff --git a/file.go b/file.go
index e2ebcf4d5c6cf5a2a8c90b1e8a109f8caa4f3282..37c185c1aa72b7c7802b863347731f4de2200047 100644 (file)
--- a/file.go
+++ b/file.go
@@ -66,20 +66,20 @@ func fileBytesLeft(
        switch numPiecesSpanned {
        case 0:
        case 1:
-               if !torrentCompletedPieces.Get(fileFirstPieceIndex) {
+               if !torrentCompletedPieces.Get(bitmap.BitIndex(fileFirstPieceIndex)) {
                        left += fileLength
                }
        default:
-               if !torrentCompletedPieces.Get(fileFirstPieceIndex) {
+               if !torrentCompletedPieces.Get(bitmap.BitIndex(fileFirstPieceIndex)) {
                        left += torrentUsualPieceSize - (fileTorrentOffset % torrentUsualPieceSize)
                }
-               if !torrentCompletedPieces.Get(fileEndPieceIndex - 1) {
+               if !torrentCompletedPieces.Get(bitmap.BitIndex(fileEndPieceIndex - 1)) {
                        left += fileTorrentOffset + fileLength - int64(fileEndPieceIndex-1)*torrentUsualPieceSize
                }
                completedMiddlePieces := torrentCompletedPieces.Copy()
-               completedMiddlePieces.RemoveRange(0, fileFirstPieceIndex+1)
-               completedMiddlePieces.RemoveRange(fileEndPieceIndex-1, bitmap.ToEnd)
-               left += int64(numPiecesSpanned-2-completedMiddlePieces.Len()) * torrentUsualPieceSize
+               completedMiddlePieces.RemoveRange(0, bitmap.BitRange(fileFirstPieceIndex+1))
+               completedMiddlePieces.RemoveRange(bitmap.BitRange(fileEndPieceIndex-1), bitmap.ToEnd)
+               left += int64(numPiecesSpanned-2-pieceIndex(completedMiddlePieces.Len())) * torrentUsualPieceSize
        }
        return
 }