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/node-save-to-file-system.js')
-rw-r--r--examples/node-save-to-file-system.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/examples/node-save-to-file-system.js b/examples/node-save-to-file-system.js
new file mode 100644
index 0000000..5b33d0c
--- /dev/null
+++ b/examples/node-save-to-file-system.js
@@ -0,0 +1,16 @@
+var WebTorrent = require('webtorrent')
+var fs = require('fs')
+
+var client = new WebTorrent()
+
+client.download(magnet_uri, function (torrent) {
+ // Got torrent metadata!
+ console.log('Torrent info hash:', torrent.infoHash)
+
+ torrent.files.forEach(function (file) {
+ // Stream each file to the disk
+ var source = file.createReadStream()
+ var destination = fs.createWriteStream(file.name)
+ source.pipe(destination)
+ })
+})