Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2013-10-24 03:05:06 +0400
committerFeross Aboukhadijeh <feross@feross.org>2013-10-24 03:05:06 +0400
commitda6c52678586ac37e95791825dcfcff7df4c1756 (patch)
tree79349b07db4a0d4761a4f4c7bf32562f1a1665d2 /itty-bitty.js
parent6f79b43c54e9a6148eeecb945d9c45d703078413 (diff)
Add example to download torrent with itty-bitty-torrent
Diffstat (limited to 'itty-bitty.js')
-rw-r--r--itty-bitty.js31
1 files changed, 31 insertions, 0 deletions
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