From bb07d4db0e213611899d834b022e00936172557e Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Mon, 26 Jan 2015 18:04:18 -0800 Subject: JavaScript Standard Style --- examples/browser-download.js | 45 ++++++++++++++++++------------------ examples/browser-seed.js | 24 +++++++++---------- examples/browser-stream-to-audio.js | 39 ++++++++++++++++--------------- examples/browser-stream-to-video.js | 39 ++++++++++++++++--------------- examples/node-save-to-file-system.js | 33 +++++++++++++------------- 5 files changed, 92 insertions(+), 88 deletions(-) (limited to 'examples') diff --git a/examples/browser-download.js b/examples/browser-download.js index 3428f72..a60e3bd 100644 --- a/examples/browser-download.js +++ b/examples/browser-download.js @@ -1,22 +1,23 @@ -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) - }) - }) -}) +var WebTorrent = require('webtorrent') + +var client = new WebTorrent() +var magnetUri = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36' + +client.add(magnetUri, 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) + }) + }) +}) diff --git a/examples/browser-seed.js b/examples/browser-seed.js index 6a6d498..cad1061 100644 --- a/examples/browser-seed.js +++ b/examples/browser-seed.js @@ -1,12 +1,12 @@ -var dragDrop = require('drag-drop/buffer') -var WebTorrent = require('webtorrent') - -var client = new WebTorrent() - -// When user drops files on the browser, create a new torrent and start seeding it! -dragDrop('body', function (files) { - client.seed(files, function onTorrent (torrent) { - // Client is seeding the file! - console.log('Torrent info hash:', torrent.infoHash) - }) -}) +var dragDrop = require('drag-drop/buffer') +var WebTorrent = require('webtorrent') + +var client = new WebTorrent() + +// When user drops files on the browser, create a new torrent and start seeding it! +dragDrop('body', function (files) { + client.seed(files, function onTorrent (torrent) { + // Client is seeding the file! + console.log('Torrent info hash:', torrent.infoHash) + }) +}) diff --git a/examples/browser-stream-to-audio.js b/examples/browser-stream-to-audio.js index 84dfdfd..01c6499 100644 --- a/examples/browser-stream-to-audio.js +++ b/examples/browser-stream-to-audio.js @@ -1,19 +1,20 @@ -var WebTorrent = require('webtorrent') - -var client = new WebTorrent() - -client.add(magnet_uri, function (torrent) { - // Got torrent metadata! - console.log('Torrent info hash:', torrent.infoHash) - - // Let's say the first file is an mp3 audio file - var file = torrent.files[0] - - // Create an audio element - var audio = document.createElement('audio') - audio.controls = true - document.body.appendChild(audio) - - // Stream the audio into the audio tag - file.createReadStream().pipe(audio) -}) +var WebTorrent = require('webtorrent') + +var client = new WebTorrent() +var magnetUri = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36' + +client.add(magnetUri, function (torrent) { + // Got torrent metadata! + console.log('Torrent info hash:', torrent.infoHash) + + // Let's say the first file is an mp3 audio file + var file = torrent.files[0] + + // Create an audio element + var audio = document.createElement('audio') + audio.controls = true + document.body.appendChild(audio) + + // Stream the audio into the audio tag + file.createReadStream().pipe(audio) +}) diff --git a/examples/browser-stream-to-video.js b/examples/browser-stream-to-video.js index 7943a64..e721cee 100644 --- a/examples/browser-stream-to-video.js +++ b/examples/browser-stream-to-video.js @@ -1,19 +1,20 @@ -var WebTorrent = require('webtorrent') - -var client = new WebTorrent() - -client.add(magnet_uri, function (torrent) { - // Got torrent metadata! - console.log('Torrent info hash:', torrent.infoHash) - - // Let's say the first file is a webm (vp8) or mp4 (h264) video... - var file = torrent.files[0] - - // Create a video element - var video = document.createElement('video') - video.controls = true - document.body.appendChild(video) - - // Stream the video into the video tag - file.createReadStream().pipe(video) -}) +var WebTorrent = require('webtorrent') + +var client = new WebTorrent() +var magnetUri = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36' + +client.add(magnetUri, function (torrent) { + // Got torrent metadata! + console.log('Torrent info hash:', torrent.infoHash) + + // Let's say the first file is a webm (vp8) or mp4 (h264) video... + var file = torrent.files[0] + + // Create a video element + var video = document.createElement('video') + video.controls = true + document.body.appendChild(video) + + // Stream the video into the video tag + file.createReadStream().pipe(video) +}) diff --git a/examples/node-save-to-file-system.js b/examples/node-save-to-file-system.js index 5b33d0c..1d5e7e6 100644 --- a/examples/node-save-to-file-system.js +++ b/examples/node-save-to-file-system.js @@ -1,16 +1,17 @@ -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) - }) -}) +var WebTorrent = require('webtorrent') +var fs = require('fs') + +var client = new WebTorrent() +var magnetUri = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36' + +client.download(magnetUri, 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) + }) +}) -- cgit v1.2.3