Discussion:
[libtorrent] piece size?
Alexander Dyagilev
2017-04-12 16:37:55 UTC
Permalink
Hello,

What is the correct way to get one?

It seems that:

constautosizePerPiece=t->total_size()/s.pieces.size();

is NOT a correct one?
m***@beroal.in.ua
2017-04-12 16:50:52 UTC
Permalink
Hi. The correct value is torrent_info.piece_length(). It is always 2^n
where n is a natural number.
Post by Alexander Dyagilev
Hello,
What is the correct way to get one?
constautosizePerPiece=t->total_size()/s.pieces.size();
is NOT a correct one?
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Libtorrent-discuss mailing list
https://lists.sourceforge.net/lists/listinfo/libtorrent-discuss
Arvid Norberg
2017-04-12 17:28:51 UTC
Permalink
Post by m***@beroal.in.ua
Hi. The correct value is torrent_info.piece_length(). It is always 2^n
where n is a natural number.
That's actually not guaranteed. It's very common to be the case though.
There are some torrents where the piece size is a multiple of 16 kB (but
not a power of 2) and there's nothing stopping a torrent from having any
arbitrary piece size either. It cannot be 0 or negative though.
Post by m***@beroal.in.ua
Post by Alexander Dyagilev
Hello,
What is the correct way to get one?
constautosizePerPiece=t->total_size()/s.pieces.size();
is NOT a correct one?
assuming "s" is a torrent_info object, you can either call
torrent_info::piece_size(int) and specify which piece you're interested in.
The last piece is likely smaller than the others.

If you want the piece size used for all pieces but the last one, you can
call torrent_info::piece_length().
--
Arvid Norberg
m***@beroal.in.ua
2017-04-12 18:38:20 UTC
Permalink
Thank you for the correction.
Post by Arvid Norberg
Post by m***@beroal.in.ua
Hi. The correct value is torrent_info.piece_length(). It is always 2^n
where n is a natural number.
That's actually not guaranteed. It's very common to be the case though.
There are some torrents where the piece size is a multiple of 16 kB (but
not a power of 2) and there's nothing stopping a torrent from having any
arbitrary piece size either. It cannot be 0 or negative though.
Continue reading on narkive:
Loading...