Comparing version 1.2.0 to 1.3.0
25
index.js
@@ -17,2 +17,3 @@ var raf = require('random-access-file') | ||
this._feeds = {} | ||
this._feedKeyToFeed = {} | ||
@@ -48,2 +49,8 @@ this._hypercore = hypercore | ||
Multicore.prototype._addFeed = function (feed, name) { | ||
this._feeds[name] = feed | ||
this._feedKeyToFeed[feed.key.toString('hex')] = feed | ||
this.emit('feed', feed, name) | ||
} | ||
Multicore.prototype.ready = function (cb) { | ||
@@ -66,5 +73,5 @@ this._ready(cb) | ||
if (!err && name) { | ||
self._feeds[name] = feed | ||
self._addFeed(feed, name) | ||
} else { | ||
self._feeds[''+n] = feed | ||
self._addFeed(feed, String(n)) | ||
} | ||
@@ -109,4 +116,3 @@ }) | ||
feed.ready(function () { | ||
self._feeds[idx] = feed | ||
self.emit('feed', feed, idx) | ||
self._addFeed(feed, String(idx)) | ||
release(function () { | ||
@@ -126,7 +132,5 @@ cb(null, feed, idx) | ||
Multicore.prototype.feed = function (key) { | ||
var feeds = Object.values(this._feeds) | ||
for (var i = 0; i < feeds.length; i++) { | ||
if (feeds[i].key.equals(key)) return feeds[i] | ||
} | ||
return null | ||
if (Buffer.isBuffer(key)) key = key.toString('hex') | ||
if (typeof key === 'string') return this._feedKeyToFeed[key] | ||
else return null | ||
} | ||
@@ -153,4 +157,3 @@ | ||
var feed = self._hypercore(storage, key, self._opts) | ||
self._feeds[numFeeds] = feed | ||
self.emit('feed', feed, String(numFeeds)) | ||
self._addFeed(feed, String(numFeeds)) | ||
replicate() | ||
@@ -157,0 +160,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"author": "Stephen Whitmore <sww@eight.net>", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "url": "git://github.com/noffle/multifeed.git" |
@@ -92,3 +92,3 @@ # multifeed | ||
Fetch a feed by its key `key` (a `Buffer`). | ||
Fetch a feed by its key `key` (a `Buffer` or hex string). | ||
@@ -95,0 +95,0 @@ ### var stream = multi.replicate([opts]) |
@@ -33,3 +33,3 @@ var test = require('tape') | ||
test('get feed by key', function (t) { | ||
t.plan(2) | ||
t.plan(3) | ||
@@ -41,3 +41,5 @@ var multi = multicore(hypercore, ram, { valueEncoding: 'json' }) | ||
var feed = multi.feed(w.key) | ||
t.deepEquals(feed, w, 'writer is the same as retrieved feed') | ||
t.deepEquals(feed, w, 'writer is the same as retrieved feed (buffer key)') | ||
feed = multi.feed(w.key.toString('hex')) | ||
t.deepEquals(feed, w, 'writer is the same as retrieved feed (hex key)') | ||
}) | ||
@@ -44,0 +46,0 @@ }) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
15998
379
0