Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocks associated with file #71

Open
sneurlax opened this issue Jun 15, 2014 · 4 comments
Open

Blocks associated with file #71

sneurlax opened this issue Jun 15, 2014 · 4 comments
Labels

Comments

@sneurlax
Copy link

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.

@BastienClement
Copy link
Collaborator

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);

@amilajack
Copy link
Contributor

@galedric @jaruba How can I get the pieceLength in this example?

@jaruba
Copy link
Contributor

jaruba commented May 25, 2016

@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.

@amilajack
Copy link
Contributor

@jaruba Thank! Sorry for late response. I must have missed the notification.

Also, how is @galedric is getting his file object?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants