Skip to content

Instantly share code, notes, and snippets.

@chrisnharvey
Created February 25, 2016 21:03
Show Gist options
  • Save chrisnharvey/5b229d108a6dc2a02fbb to your computer and use it in GitHub Desktop.
Save chrisnharvey/5b229d108a6dc2a02fbb to your computer and use it in GitHub Desktop.
Webtorrent test
var WebTorrent = require('webtorrent')
var fs = require('fs')
var client = new WebTorrent()
var magnetURI = 'test.torrent'
client.download(magnetURI, function (torrent) {
// Got torrent metadata!
console.log('Torrent magnet link:', torrent.magnetURI)
torrent.files.forEach(function (file) {
// Stream each file to the disk
var source = file.createReadStream()
var destination = fs.createWriteStream(file.name)
source.pipe(destination)
})
})
console.log(client.torrents[0])
client.torrents[0].on('download', function() {
console.log(client.torrents[0].progress)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment