Jump to content

Torrent files: Length field Vs Piece length/Pieces


druha

Recommended Posts

Hi, im developing a BT client for a university project and I have found some trouble understanding the information about the file to download provided in the torrent file. As far as I know, in the "pieces" field there is one Sha1 value for every piece that forms the target file, and piece length is the size of every field. So the final file should be pieces*piece length bytes long.

But then there is some torrent like this: pieces=20, piece length=65536, length=24... Shouldnt it be length=pieces*piece length? How should I interpret this information?

Thanks in advance.

Link to comment
Share on other sites

...? When you say pieces=20, are you saying that the pieces key in the info dictionary is 20 bytes long? If so, that's only one SHA1 hash, meaning it's only one piece, and so the length key will only be at most one piece length.

Keep in mind that the last piece won't always be a full piece size, so that the final size won't necessarily be exactly (piece count * piece length) long.

As well, mind the fact that files in multi-file torrents may (and usually do) share edge pieces with other files.

Link to comment
Share on other sites

Ok I think got this a little clearer now. Now I remember reading what you said, that every piece corresponds to one 20-byte Sha1 value, i got that twisted. With regards the piece length thing, the actual question would be, can i have a file smaller than the piece length specified in the torrent? (from your answer im guessing that it is possible, but i want to make sure i understood it).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...