mafintosh / torrent-stream

The low level streaming torrent engine that peerflix uses
MIT License
1.94k stars 227 forks source link

Specific file selection grabbing more file than expected #131

Closed zoo1 closed 8 years ago

zoo1 commented 8 years ago
            engine.on('ready', function () {
            engine.files.forEach(function (file){
            if(file.name === singlefile)
            {
                file.select()
                console.log(file.name)
            }
            else
                file.deselect()

I am running the above code, and the torrent seems to be grabbing files outside of desired single file I have selected. Is there an issue with my code of is this a bug?

asapach commented 8 years ago

This is how bittorrent works: all the files in a torrent are stored as a continuous array of bytes split into a lot of pieces of the same size. Piece size varies from 32KB to several MB. There can more than one file in a single piece. So when you do file.select() it actually downloads all the pieces that comprise that particular file, and if it overlaps with other files, some of them (or some of their parts) will be downloaded as well.

zoo1 commented 8 years ago

Thanks for the clarification.