Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix torrent file download corruption

  • Loading branch information...
commit feb7f14c556f66b584e1268e1869775d7fd1dea1 1 parent a7e51fb
@feross authored
Showing with 15 additions and 9 deletions.
  1. +8 −4 lib/app.js
  2. +7 −5 lib/torrent.js
View
12 lib/app.js
@@ -96,7 +96,7 @@ App.prototype.addTorrent = function (torrent) {
self.updateTorrentUI($torrent, torrent)
$torrent.on('click', function () {
- self.downloadTorrentMetadata(torrent)
+ self.downloadTorrentFile(torrent)
})
$('#torrents').append($torrent)
@@ -148,7 +148,7 @@ App.prototype.updateTorrentUI = function ($torrent, torrent) {
.text(humanize.filesize(torrent.swarm.uploadSpeed()))
}
-App.prototype.downloadTorrentMetadata = function (torrent) {
+App.prototype.downloadTorrentFile = function (torrent) {
var self = this
if (!torrent.metadata)
return
@@ -170,9 +170,13 @@ App.prototype.downloadTorrentMetadata = function (torrent) {
console.log('write complete')
}
- var metadata = new Buffer(bncode.encode(torrent.metadata))
+ var metadata = bncode.encode({
+ 'announce-list': [],
+ infoHash: torrent.infoHash,
+ info: bncode.decode(torrent.metadataRaw)
+ })
writer.write(new Blob([metadata]), { type: 'application/x-bittorrent' })
}, errorHandler)
})
-}
+}
View
12 lib/torrent.js
@@ -26,6 +26,8 @@ function Torrent (uri, opts) {
self.infoHash = info.infoHash
self.title = info.title
+
+ self.metadataRaw = null
self.metadata = null
self.file = null
@@ -172,11 +174,9 @@ Torrent.prototype._onUtMetadata = function (wire, buf) {
case 1:
data.copy(wire.metadata, dict.piece * METADATA_BLOCK_SIZE)
- self.metadata = {
- 'announce-list': [],
- info: bncode.decode(wire.metadata)
- }
- self.emit('metadata', this.metadata)
+ self.metadataRaw = wire.metadata
+ self.metadata = bncode.decode(wire.metadata)
+ self.onMetadata(self.metadata)
break
// ut_metadata reject (peer doesn't have piece we requested)
// {'msg_type': 2, 'piece': 0}
@@ -186,6 +186,8 @@ Torrent.prototype._onUtMetadata = function (wire, buf) {
}
}
+Torrent.prototype.onMetadata = function (metadata) {
+}
//
// HELPER METHODS
//
Please sign in to comment.
Something went wrong with that request. Please try again.