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:
Diffstat (limited to 'examples/browser-download.js')
-rw-r--r--examples/browser-download.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/examples/browser-download.js b/examples/browser-download.js
new file mode 100644
index 0000000..3428f72
--- /dev/null
+++ b/examples/browser-download.js
@@ -0,0 +1,22 @@
+var WebTorrent = require('webtorrent')
+
+var client = new WebTorrent()
+
+client.add(magnet_uri, function (torrent) {
+ // Got torrent metadata!
+ console.log('Torrent info hash:', torrent.infoHash)
+
+ torrent.files.forEach(function (file) {
+ // Get a url for each file
+ file.getBlobURL(function (err, url) {
+ if (err) throw err
+
+ // Add a link to the page
+ var a = document.createElement('a')
+ a.download = file.name
+ a.href = url
+ a.textContent = 'Download ' + file.name
+ document.body.appendChild(a)
+ })
+ })
+})