Created
February 25, 2016 21:03
-
-
Save chrisnharvey/5b229d108a6dc2a02fbb to your computer and use it in GitHub Desktop.
Webtorrent test
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 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