Skip to content

Instantly share code, notes, and snippets.

@Tercus
Created April 6, 2016 00:17
Show Gist options
  • Save Tercus/6491cb4dd2d8107714c4c3b7557eddbc to your computer and use it in GitHub Desktop.
Save Tercus/6491cb4dd2d8107714c4c3b7557eddbc to your computer and use it in GitHub Desktop.
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