Permalink
Browse files

torrent successfully fetched over the net!

  • Loading branch information...
feross committed Mar 3, 2014
1 parent 8375be8 commit 07013a122d6ea7e4ee066998467993315fd39e49
Showing with 8 additions and 3 deletions.
  1. +2 −1 lib/app.js
  2. +5 −2 lib/storage.js
  3. +1 −0 lib/torrent.js
View
@@ -168,7 +168,8 @@ App.prototype.downloadTorrentFile = function (torrent) {
console.log('write complete')
}
- writer.write(new Blob([torrent.torrentFile]), { type: 'application/x-bittorrent' })
+ // TODO: remove torrent.file from here!
+ writer.write(new Blob([torrent.file || torrent.torrentFile]), { type: 'application/x-bittorrent' })
}, errorHandler)
})
}
View
@@ -155,7 +155,7 @@ function File (file, buffer, pieces) {
File.prototype._checkDone = function () {
var self = this
self.done = self.pieces.every(function (piece) {
- return piece.done
+ return piece.verified
})
if (self.done)
self.emit('done')
@@ -222,7 +222,7 @@ Object.defineProperty(Storage.prototype, 'numMissing', {
var self = this
var numMissing = 0
for (var index = 0, len = self.pieces.length; index < len; index++) {
- numMissing += self.bitfield.get(index)
+ numMissing += (self.bitfield.get(index) === 0)
}
return numMissing
}
@@ -269,6 +269,9 @@ Storage.prototype._onPieceDone = function (piece) {
Storage.prototype._onFileDone = function (file) {
var self = this
self.emit('file', file)
+
+ // TODO
+ self.emit('done')
}
function sha1 (buf) {
View
@@ -272,6 +272,7 @@ Torrent.prototype._onMetadata = function () {
self.storage.on('piece', self._onStoragePiece.bind(self))
self.storage.on('file', function (file) {
console.log('FILE', file.name)
+ self.file = file.buffer
})
self.storage.on('done', function () {
console.log('done with torrent!')

0 comments on commit 07013a1

Please sign in to comment.