Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

multifeed

Package Overview
Dependencies
Maintainers
2
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multifeed - npm Package Compare versions

Comparing version 1.3.4 to 1.3.5

todo.json

41

index.js

@@ -143,3 +143,4 @@ var raf = require('random-access-file')

function addMissingKeys (keys) {
function addMissingKeys (keys, cb) {
var pending = 0
keys.forEach(function (key) {

@@ -150,2 +151,3 @@ var feeds = Object.values(self._feeds).filter(function (feed) {

if (!feeds.length) {
pending++
var numFeeds = Object.keys(self._feeds).length

@@ -155,5 +157,8 @@ var storage = self._storage(''+numFeeds)

self._addFeed(feed, String(numFeeds))
feed.replicate(opts)
feed.ready(function () {
if (!--pending) cb()
})
}
})
if (!pending) cb()
}

@@ -175,5 +180,8 @@

var readStream = through(function (buf, _, next) {
var self = this
if (firstRead) {
firstRead = false
var keys = deserializeFeedBuf(buf)
var res = deserializeFeedBuf(buf)
var keys = res[0]
var size = res[1]
if (!Array.isArray(keys)) {

@@ -183,7 +191,14 @@ // probably replicating with a non-multifeed peer: abort

}
addMissingKeys(keys)
// push remainder of buffer
this.push(buf.slice(size))
addMissingKeys(keys, function () {
startSync()
next()
})
} else {
this.push(buf)
next()
}
next()
})

@@ -206,2 +221,12 @@

function startSync () {
var sortedFeeds = Object.values(self._feeds).sort(cmp)
function cmp (a, b) {
return a.key.toString('hex') < b.key.toString('hex')
}
sortedFeeds.forEach(function (feed) {
feed.replicate(opts)
})
}
function onready (err) {

@@ -212,6 +237,2 @@ if (err) return stream.destroy(err)

self._fake.replicate(opts)
Object.values(self._feeds).forEach(function (feed) {
feed.replicate(opts)
})
}

@@ -241,3 +262,3 @@ }

return res
return [res, 2 + numFeeds * 32]
}

@@ -244,0 +265,0 @@

@@ -5,3 +5,3 @@ {

"author": "Stephen Whitmore <sww@eight.net>",
"version": "1.3.4",
"version": "1.3.5",
"repository": {

@@ -19,7 +19,7 @@ "url": "git://github.com/noffle/multifeed.git"

"dependencies": {
"duplexify": "^3.5.4",
"duplexify": "^3.6.0",
"hypercore-protocol": "^6.6.4",
"inherits": "^2.0.3",
"mutexify": "^1.2.0",
"pumpify": "^1.4.0",
"pumpify": "^1.5.1",
"random-access-file": "^2.0.1",

@@ -29,3 +29,3 @@ "through2": "^2.0.3"

"devDependencies": {
"hypercore": "^6.14.0",
"hypercore": "^6.18.1",
"random-access-memory": "^2.4.0",

@@ -32,0 +32,0 @@ "standard": "~10.0.0",

@@ -116,2 +116,58 @@ var test = require('tape')

test('live replicate two multifeeds', function (t) {
t.plan(22)
var m1 = multifeed(hypercore, ram, { valueEncoding: 'json' })
var m2 = multifeed(hypercore, ram, { valueEncoding: 'json' })
var feedEvents1 = 0
var feedEvents2 = 0
m1.on('feed', function (feed, name) {
t.equals(name, String(feedEvents1))
feedEvents1++
})
m2.on('feed', function (feed, name) {
t.equals(name, String(feedEvents2))
feedEvents2++
})
function setup (m, buf, cb) {
m.writer(function (err, w) {
t.error(err)
w.append(buf, function (err) {
t.error(err)
w.get(0, function (err, data) {
t.error(err)
t.equals(data, buf)
t.deepEquals(m.feeds(), [w])
cb()
})
})
})
}
setup(m1, 'foo', function () {
setup(m2, 'bar', function () {
var r = m1.replicate({live:true})
r.pipe(m2.replicate({live:true})).pipe(r)
setTimeout(check, 1000)
})
})
function check () {
t.equals(m1.feeds().length, 2)
t.equals(m2.feeds().length, 2)
m1.feeds()[1].get(0, function (err, data) {
t.error(err)
t.equals(data, 'bar')
})
m2.feeds()[1].get(0, function (err, data) {
t.error(err)
t.equals(data, 'foo')
})
t.equals(feedEvents1, 2)
t.equals(feedEvents2, 2)
}
})
test('get localfeed by name across disk loads', function (t) {

@@ -118,0 +174,0 @@ t.plan(5)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc