Skip to content

Instantly share code, notes, and snippets.

@adregan
Last active August 29, 2015 14:07
Show Gist options
  • Save adregan/56ef6a27803bb7621152 to your computer and use it in GitHub Desktop.
Save adregan/56ef6a27803bb7621152 to your computer and use it in GitHub Desktop.
module.exports = function(counter) {
var duplexer = require('duplexer')
, through = require('through')
, thr = through(write)
, countries = {}
;
return duplexer(thr, counter);
function write(buf) {
if (countries.hasOwnProperty(buf.country)) {
countries[buf.country] += 1;
}
else {
countries[buf.country] = 1;
}
}
function end(buf) {
counter.setCounts(countries);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment