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
path: root/lib
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2016-02-22 05:31:35 +0300
committerFeross Aboukhadijeh <feross@feross.org>2016-02-22 05:31:35 +0300
commitf1d2f0d40a9267e35fbe863e6d72f1521523fbaf (patch)
treea7fd8189c70d800685725fb0f797a6e6074472ae /lib
parentaadcb1c16585772adc3969e3a96823eeafe1dc05 (diff)
torrent: Attempt to set infoHash property synchronously
Diffstat (limited to 'lib')
-rw-r--r--lib/torrent.js25
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/torrent.js b/lib/torrent.js
index 0a1a03a..f14cf4e 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -187,11 +187,26 @@ Object.defineProperty(Torrent.prototype, 'torrentFileBlobURL', {
Torrent.prototype._onTorrentId = function (torrentId) {
var self = this
if (self.destroyed) return
- parseTorrent.remote(torrentId, function (err, parsedTorrent) {
- if (self.destroyed) return
- if (err) return self._onError(err)
- self._onParsedTorrent(parsedTorrent)
- })
+
+ var parsedTorrent
+ try { parsedTorrent = parseTorrent(torrentId) } catch (err) {}
+
+ if (parsedTorrent) {
+ // Attempt to set infoHash property synchronously
+ self.infoHash = parsedTorrent.infoHash
+ process.nextTick(function () {
+ if (self.destroyed) return
+ self._onParsedTorrent(parsedTorrent)
+ })
+ } else {
+ // If torrentId failed to parse, it could be in a form that requires an async
+ // operation, i.e. http/https link, filesystem path, or Blob.
+ parseTorrent.remote(torrentId, function (err, parsedTorrent) {
+ if (self.destroyed) return
+ if (err) return self._onError(err)
+ self._onParsedTorrent(parsedTorrent)
+ })
+ }
}
Torrent.prototype._onParsedTorrent = function (parsedTorrent) {