diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2013-10-24 03:05:06 +0400 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2013-10-24 03:05:06 +0400 |
commit | da6c52678586ac37e95791825dcfcff7df4c1756 (patch) | |
tree | 79349b07db4a0d4761a4f4c7bf32562f1a1665d2 | |
parent | 6f79b43c54e9a6148eeecb945d9c45d703078413 (diff) |
Add example to download torrent with itty-bitty-torrent
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | itty-bitty.js | 31 |
2 files changed, 33 insertions, 0 deletions
@@ -13,3 +13,5 @@ results npm-debug.log node_modules + +tmp
\ No newline at end of file diff --git a/itty-bitty.js b/itty-bitty.js new file mode 100644 index 0000000..eff2dbe --- /dev/null +++ b/itty-bitty.js @@ -0,0 +1,31 @@ +// Download a torrent with itty-bitty-torrent + +var path = require('path') + +var Torrent = require('itty-bitty-torrent') +var downloadLocation = path.join(__dirname, 'tmp') +// var torrent = 'http://releases.ubuntu.com/13.10/ubuntu-13.10-server-amd64.iso.torrent' +// var torrent = path.join(__dirname, 'torrents/leaves.torrent') +var torrent = path.join(__dirname, 'torrents/pride.torrent') + +var client = new Torrent(torrent, downloadLocation, function(err){ + if (!err) client.download() + + // Get speed + setInterval(function(){ + console.log(Math.round(client.speed()) / 1000) + }, 500) + + // Get percentage downloaded + setInterval(function(){ + console.log(Math.round(client.percentage())) + }, 10000) +}) + +client.on('finished', function(){ + console.log('finished') + // The torrent has finished downloading. +}) + +// stop our torrent downloading & seeding +// client.stop()
\ No newline at end of file |