NAME
Net::BitTorrent::BitField
INTRODUCTION
What is BitField ?
When BitTorrent client downloads files,
they require pieces instead of files. The piece are stream data of file(s).
BitField is used for checking which pieces does the client have.
Why implemented as array ?
It was a simple and an easy way.
Not much worth to optimize this class,
I thought better to choose maintenance cost.
I did not Benchmark about BitField.
It should be in ToDo but low priority, now.
Current Design of BitField
BitField stores 1 or 0 instead of boolean(true or false),
Because it can make easier to convert to bitfield binary data.
EXAMPLES
# How to get the BitField from metainfo and storage.
@bitfield = BitField.create(metainfo['info']['pieces'],
storage.get_pieces)
# Check the client have the piece.
def have?(index)
return (@bitfield[index] == 1) ? true : false
end
SEE ALSO
NOTES
- TODO Check length of field on fetch/store time
- TODO Store element []= takes 0 or 1.
- TODO Optimize BitField array to string.
AUTHORS