UNPKG

plasmid

Version:

A low-level implementation of the anti-entropy gossip protocol scuttlebutt.

32 lines (25 loc) 668 B
'use strict' var Transform = require('stream').Transform var GossipTransform = module.exports = function(host) { this.host = host this.digest = [] Transform.call(this, { objectMode: true }) } GossipTransform.prototype = Object.create(Transform.prototype, { constructor: { value: GossipTransform } }) GossipTransform.prototype._transform = function(obj, enc, cont) { this.digest.push(obj) if (obj.done === true) { this.writeDeltas() } cont() } GossipTransform.prototype._flush = function(done) { this.writeDeltas() done() } GossipTransform.prototype.writeDeltas = function() { this.host.getDeltas(this.digest, this) this.digest = [] }