diff options
author | Joseph Dykstra <josephdykstra@gmail.com> | 2015-01-17 01:45:13 +0300 |
---|---|---|
committer | Joseph Dykstra <josephdykstra@gmail.com> | 2015-01-17 01:45:13 +0300 |
commit | 777d6c2225a5fae5f514a141ea3ec25d97763754 (patch) | |
tree | 88a5d6d433e7ce9c9a0f0c995fbdafbdbf59378e /examples/node-save-to-file-system.js | |
parent | d880b81ff83a860594a5310dd0a05fdb1ca7f876 (diff) |
Added ./examples/ directory
Diffstat (limited to 'examples/node-save-to-file-system.js')
-rw-r--r-- | examples/node-save-to-file-system.js | 16 |
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)
+ })
+})
|