# Download a piece #nd2 (File size does not match expected file size)

**URL:** <https://forum.codecrafters.io/t/download-a-piece-nd2-file-size-does-not-match-expected-file-size/1277>\
**Category:** Challenges\
**Tags:** challenge:bittorrent\
**Created:** [August 4, 2024, 12:41pm UTC](https://forum.codecrafters.io/t/download-a-piece-nd2-file-size-does-not-match-expected-file-size/1277 "2024-08-04T12:41:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yehor-dykhov](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/yehor-dykhov/32/913_2.png) [@yehor-dykhov](https://forum.codecrafters.io/u/yehor-dykhov)\
**Post date:** [August 4, 2024, 12:41pm UTC](https://forum.codecrafters.io/t/download-a-piece-nd2-file-size-does-not-match-expected-file-size/1277/1 "2024-08-04T12:41:53Z")

</div>

I’m stuck on Stage #nd2.

I have loaded the piece that have correct _length_ and _hash_ (the torrent file info), but test says that:  
“File size does not match expected file size. Expected: 190404 Actual: 262144”

 ![Screenshot_2](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/4/4c2df33e6a1fa2b5659e0cffe816e261177cea92.png)

Here are my logs:

```auto
NITROROOT% codecrafters test
Initiating test run...

⚡ This is a turbo test run. https://codecrafters.io/turbo

Running tests. Logs should appear shortly...

[compile] Compiling bittorrent-starter-rust v0.1.0 (/app)
[compile] Finished release [optimized] target(s) in 5.16s
[compile] Compilation successful.

Debug = true

[tester::#ND2] Running tests for Stage #ND2 (Download a piece)
9 /tmp/torrents878677958/itsworking.gif.torrent 9
[your_program] IPS: [("178.62.85.20", "51493"), ("165.232.33.77", "51495"), ("178.62.82.89", "51415")]
[your_program] torrent.info.length: 2549700
[your_program] torrent.info.piece_length: 262144
[your_program] piece_hash: 01cc17bbe60fa5a52f64bd5f5b64d99286d50aa5
[your_program] info piece hashes: ["01cc17bbe60fa5a52f64bd5f5b64d99286d50aa5", "838f703cf7f6f08d1c497ed390df78f90d5f7566", "45bf10974b5816491e30628b78a382ca36c4e05f", "84be4bd855b34bcedc0c6e98f66d3e7c63353d1e", "86427ac94d6e4f21a6d0d6c8b7ffa4c393c3b131", "7c70cd5f44d1ac5505cb855d526ceb0f5f1cd5e3", "3796ab05af1fa874173a0a6c1298625ad47b4fe6", "272a8ff8fc865b053d974a78681414b38077d7b1", "b07128d3a6018062bfe779db96d3a93c05fb81d4", "7affc94f0985b985eb888a36ec92652821a21be4"]
[your_program] to file len: 262144
[your_program] Piece 9 downloaded to /tmp/torrents878677958/piece-9.
[tester::#ND2] File size does not match expected file size. Expected: 190404 Actual: 262144

[tester::#ND2] Test failed

View our article on debugging test failures: https://codecrafters.io/debug

```

---

<div class="post-metadata">

**Author:** ![sarp](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/sarp/32/1082_2.png) [@sarp](https://forum.codecrafters.io/u/sarp)\
**Post date:** [August 6, 2024, 10:12am UTC](https://forum.codecrafters.io/t/download-a-piece-nd2-file-size-does-not-match-expected-file-size/1277/2 "2024-08-06T10:12:37Z")

</div>

Last piece of the file can be less than `piece length` defined in the torrent file. For example, say `file length` is `92063 bytes` and `piece length` is `32768 bytes`. This file will consist of 3 pieces:

- 1st piece with `32768 bytes`
- 2nd piece with `32768 bytes`
- 3rd piece with only `26527 bytes`.

It seems like you have the same issue, it’s downloading the last piece and the length of the last piece is less than piece length.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [August 11, 2024, 10:13am UTC](https://forum.codecrafters.io/t/download-a-piece-nd2-file-size-does-not-match-expected-file-size/1277/3 "2024-08-11T10:13:17Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
