Created
April 6, 2016 00:17
-
-
Save Tercus/6491cb4dd2d8107714c4c3b7557eddbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var download = request.payload | |
console.log('infoHash of torrent to download: ' + download) | |
var opts = { | |
path: './storage/' + download + '/', | |
announce: ['ws://localhost:8080'] | |
} | |
client.add(download, opts, function (torrent) { | |
console.log('added torrent') | |
torrent.files.forEach(function (file) { | |
console.log('Started saving ' + file.name) | |
file.getBuffer(function (err, buffer) { | |
if (err) { | |
console.error('Error downloading ' + file.name) | |
return | |
} | |
fs.writeFile(file.name, buffer, function (err) { | |
console.error('Error saving ' + file.name) | |
}) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment