Open sneurlax opened 10 years ago
In torrent-stream, this is handled by the storage backend.
https://github.com/mafintosh/torrent-stream/blob/master/lib/storage.js
Unfortunately, the piecesMap
object is not publicly available. The main logic however is quite simple.
var fileStart = file.offset;
var fileEnd = file.offset + file.length;
var firstPiece = Math.floor(fileStart / pieceLength);
var lastPiece = Math.floor((fileEnd - 1) / pieceLength);
@galedric @jaruba How can I get the pieceLength in this example?
@amilajack
var peerflix = require('peerflix'),
engine = peerflix(magnetLink);
engine.server.on('listening', function() {
console.log('Piece length: ' + engine.torrent.pieceLength);
});
Should work, I didn't test it though.
@jaruba Thank! Sorry for late response. I must have missed the notification.
Also, how is @galedric is getting his file
object?
In a multi-file torrent (read: not typical movie torrents as used with peerflix, popcorn time, etc., i.e. music albums,) how would I find the blocks (piece-indexes) associated with each file?
Specifically: engine.on('download') emits a piece-index; how do I know where that lies within a file? That is, is there a way to tell that a file consists of blocks 52-79?
Thanks for reading. I'll document as I figure this out.