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:
-rw-r--r--README.md12
-rw-r--r--index.js4
-rw-r--r--package.json1
-rw-r--r--test/basic.js79
4 files changed, 65 insertions, 31 deletions
diff --git a/README.md b/README.md
index e38f176..a7b1de9 100644
--- a/README.md
+++ b/README.md
@@ -217,14 +217,14 @@ If `opts` is specified, then the default options (shown below) will be overridde
Start downloading a new torrent. Aliased as `client.download`.
-`torrentId` can be any of the following:
+`torrentId` can be one of:
-- info hash (as a hex string or Buffer)
-- magnet uri (as a utf8 string)
-- .torrent file (as a Buffer)
+- magnet uri (utf8 string)
+- torrent file (buffer)
+- info hash (hex string or buffer)
- parsed torrent (from [parse-torrent](https://github.com/feross/parse-torrent))
-- http/https url to a .torrent file (string)
-- filesystem path to a .torrent file (string)
+- http/https url to a torrent file (string)
+- filesystem path to a torrent file (string)
If `ontorrent` is specified, then it will be called when **this** torrent is ready to be
used (i.e. metadata is available). Note: this is distinct from the 'torrent' event which
diff --git a/index.js b/index.js
index 5d34651..0f58e3e 100644
--- a/index.js
+++ b/index.js
@@ -135,8 +135,8 @@ WebTorrent.prototype.get = function (torrentId) {
* - torrent file (buffer)
* - info hash (hex string or buffer)
* - parsed torrent (from [parse-torrent](https://github.com/feross/parse-torrent))
- * - http/https url to a .torrent file (string)
- * - filesystem path to a .torrent file (string)
+ * - http/https url to a torrent file (string)
+ * - filesystem path to a torrent file (string)
*
* @param {string|Buffer|Object} torrentId
* @param {Object} opts torrent-specific options
diff --git a/package.json b/package.json
index 76e3d35..f574f64 100644
--- a/package.json
+++ b/package.json
@@ -70,6 +70,7 @@
"bittorrent-tracker": "^2.5.0",
"brfs": "^1.2.0",
"browserify": "^5.11.2",
+ "portfinder": "^0.2.1",
"run-auto": "^1.0.0",
"tape": "2.x",
"uglify-js": "^2.4.15",
diff --git a/test/basic.js b/test/basic.js
index bd332dc..e7aaca5 100644
--- a/test/basic.js
+++ b/test/basic.js
@@ -1,36 +1,69 @@
-var BitTorrentClient = require('../')
+var WebTorrent = require('../')
+var fs = require('fs')
+var http = require('http')
var parseTorrent = require('parse-torrent')
+var portfinder = require('portfinder')
var test = require('tape')
-var fs = require('fs')
-var leaves = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
+var leavesPath = __dirname + '/torrents/leaves.torrent'
+var leaves = fs.readFileSync(leavesPath)
var leavesTorrent = parseTorrent(leaves)
-test('Test supported torrentInfo types', function (t) {
+function verify (t, client, torrent) {
+ t.equal(torrent.infoHash, leavesTorrent.infoHash)
+ client.destroy()
+}
+
+test('client.add (magnet uri, torrent file, info hash, and parsed torrent)', function (t) {
t.plan(5)
- function verify (client, torrent) {
- t.equal(torrent.infoHash, leavesTorrent.infoHash)
- client.destroy()
- }
+ // magnet uri (utf8 string)
+ var client1 = new WebTorrent({ dht: false, trackers: false })
+ verify(t, client1, client1.add('magnet:?xt=urn:btih:' + leavesTorrent.infoHash))
+
+ // torrent file (buffer)
+ var client2 = new WebTorrent({ dht: false, trackers: false })
+ verify(t, client2, client2.add(leaves))
+
+ // info hash (hex string)
+ var client3 = new WebTorrent({ dht: false, trackers: false })
+ verify(t, client3, client3.add(leavesTorrent.infoHash))
- // info hash (as a hex string)
- var client1 = new BitTorrentClient({ dht: false, trackers: false })
- verify(client1, client1.add(leavesTorrent.infoHash))
+ // info hash (buffer)
+ var client4 = new WebTorrent({ dht: false, trackers: false })
+ verify(t, client4, client4.add(new Buffer(leavesTorrent.infoHash, 'hex')))
- // info hash (as a Buffer)
- var client2 = new BitTorrentClient({ dht: false, trackers: false })
- verify(client2, client2.add(new Buffer(leavesTorrent.infoHash, 'hex')))
+ // parsed torrent (from parse-torrent)
+ var client5 = new WebTorrent({ dht: false, trackers: false })
+ verify(t, client5, client5.add(leavesTorrent))
- // magnet uri (as a utf8 string)
- var client3 = new BitTorrentClient({ dht: false, trackers: false })
- verify(client3, client3.add('magnet:?xt=urn:btih:' + leavesTorrent.infoHash))
+})
+
+test('client.add (http url to a torrent file (string))', function (t) {
+ t.plan(1)
+
+ var server = http.createServer(function (req, res) {
+ res.end(leaves)
+ })
+
+ portfinder.getPort(function (err, port) {
+ if (err) throw err
+ server.listen(port, function () {
+ var url = 'http://127.0.0.1:' + port
+ var client1 = new WebTorrent({ dht: false, trackers: false })
+ client1.add(url, function (torrent) {
+ verify(t, client1, torrent)
+ server.close()
+ })
+ })
+ })
+})
- // .torrent file (as a Buffer)
- var client4 = new BitTorrentClient({ dht: false, trackers: false })
- verify(client4, client4.add(leaves))
+test('client.add (filesystem path to a torrent file (string))', function (t) {
+ t.plan(1)
- // parsed torrent (as an Object)
- var client5 = new BitTorrentClient({ dht: false, trackers: false })
- verify(client5, client5.add(leavesTorrent))
+ var client1 = new WebTorrent({ dht: false, trackers: false })
+ client1.add(leavesPath, function (torrent) {
+ verify(t, client1, torrent)
+ })
})