Skip to content

Instantly share code, notes, and snippets.

@mattmcmanus
Created June 12, 2013 20:28
Show Gist options
  • Save mattmcmanus/5768826 to your computer and use it in GitHub Desktop.
Save mattmcmanus/5768826 to your computer and use it in GitHub Desktop.
Filter a json file using streams
var es = require('event-stream');
es.pipeline(
fs.createReadStream(ummon.config.log.path, {flags: 'r', encoding: 'utf-8'}),
es.split(),
es.parse(),
es.mapSync(function (data) {
if (key) {
if (data[key] && data[key] === val) {
return data;
}
} else {
return data;
}
}),
es.stringify(),
res
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment