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>2014-09-15 19:41:19 +0400
committerFeross Aboukhadijeh <feross@feross.org>2014-09-15 19:41:19 +0400
commit653f987537c9b4dd056f2baff4af108a386e011d (patch)
tree013656a7cfd15b5bbd53a56b9bcf5cc4c3bb28d1 /index.js
parent4e658bc8476632a149232c507b6f880054996d08 (diff)
move http/https url and filesystem support into bittorrent-client
Diffstat (limited to 'index.js')
-rw-r--r--index.js45
1 files changed, 5 insertions, 40 deletions
diff --git a/index.js b/index.js
index 35ed6eb..b5cab42 100644
--- a/index.js
+++ b/index.js
@@ -3,15 +3,11 @@
module.exports = WebTorrent
var Client = require('bittorrent-client')
-var concat = require('concat-stream')
var debug = require('debug')('webtorrent')
var extend = require('extend.js')
-var fs = require('fs')
var FSStorage = require('./lib/fs-storage')
-var hh = require('http-https')
var inherits = require('inherits')
var parallel = require('run-parallel')
-var parseTorrent = require('parse-torrent')
var Server = require('./lib/server')
inherits(WebTorrent, Client)
@@ -56,14 +52,12 @@ function WebTorrent (opts) {
WebTorrent.prototype.add =
WebTorrent.prototype.download = function (torrentId, opts, ontorrent) {
var self = this
-
+ debug('add %s', torrentId)
if (typeof opts === 'function') {
ontorrent = opts
opts = {}
}
- debug('add %s', torrentId)
-
opts = extend({
storage: typeof FSStorage === 'function' && FSStorage
}, opts)
@@ -71,40 +65,11 @@ WebTorrent.prototype.download = function (torrentId, opts, ontorrent) {
// TODO: fix this to work with multiple torrents
self.index = opts.index
- // Called once we have a torrentId that bittorrent-client can handle
- function onTorrentId (torrentId) {
- var torrent = Client.prototype.add.call(self, torrentId, opts, ontorrent)
- process.nextTick(function () {
- self.emit('add', torrent)
- })
- }
+ var torrent = Client.prototype.add.call(self, torrentId, opts, ontorrent)
- var parsed = parseTorrent(torrentId)
- if (parsed && parsed.infoHash) {
- // magnet uri, info hash, torrent file, or parsed torrent can be handled by bittorrent-client
- process.nextTick(function () {
- onTorrentId(parsed)
- })
- } else if (/^https?:/.test(torrentId)) {
- // http or https url to torrent file
- hh.get(torrentId, function (res) {
- res.pipe(concat(function (torrent) {
- onTorrentId(torrent)
- }))
- }).on('error', function (err) {
- self.emit('error', new Error('Error downloading torrent. ' + err.message))
- })
- } else {
- // assume it's a filesystem path
- fs.readFile(torrentId, function (err, torrent) {
- if (err) {
- self.emit('error', new Error('Invalid torrent. Need magnet uri, info hash, ' +
- 'torrent file, http url, or filesystem path.'))
- } else {
- onTorrentId(torrent)
- }
- })
- }
+ process.nextTick(function () {
+ self.emit('add', torrent)
+ })
return self
}