Skip to content

Commit 3b1b05a

Browse files
committed
Fix NumberOfPieces calculation
Should of course just use 20 and not PieceSize #48
1 parent 461ec2e commit 3b1b05a

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

BencodeNET.Tests/Torrents/TorrentTests.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,12 @@ public void TotalSize_UnknownFileMode_IsZero()
192192

193193
[Theory]
194194
[AutoMockedData]
195-
public void NumberOfPieces_ShouldBePiecesLengthDividedByPieceSizeRoundedUp(int piecesByteCount, long pieceSize)
195+
public void NumberOfPieces_ShouldBePiecesLengthDividedBy20(int piecesByteCount)
196196
{
197-
var expected = (int)Math.Ceiling((double) piecesByteCount/pieceSize);
197+
while (piecesByteCount % 20 != 0) piecesByteCount--;
198+
var expected = piecesByteCount / 20;
198199

199-
var torrent = new Torrent
200-
{
201-
Pieces = new byte[piecesByteCount],
202-
PieceSize = pieceSize
203-
};
200+
var torrent = new Torrent {Pieces = new byte[piecesByteCount]};
204201

205202
torrent.Pieces.Length.Should().Be(piecesByteCount);
206203
torrent.NumberOfPieces.Should().Be(expected);

BencodeNET/Torrents/Torrent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public virtual long TotalSize
219219
/// The total number of file pieces.
220220
/// </summary>
221221
public virtual int NumberOfPieces => Pieces != null
222-
? (int) Math.Ceiling((double) Pieces.Length / PieceSize)
222+
? (int) Math.Ceiling((double) Pieces.Length / 20)
223223
: 0;
224224

225225
/// <summary>

0 commit comments

Comments
 (0)