Skip to content

Instantly share code, notes, and snippets.

@mikekunze
Created September 12, 2011 21:49
Show Gist options
  • Save mikekunze/1212568 to your computer and use it in GitHub Desktop.
Save mikekunze/1212568 to your computer and use it in GitHub Desktop.
beadChips async init function
beadChip.prototype.init = function(file) {
// Localize beadChip members
var build = this.buildBeadChip;
var rows = this.rows;
var sections = this.sections;
var pass = this.pass;
var fail = this.fail;
var metricStream = fs.createReadStream(file, {
flags: 'r',
encoding: 'utf8',
mode: 0666
});
// Open file and stream data out
var allData = "";
metricStream.on('open', function(fd) {
metricStream.on('data', function(data) {
allData += data;
});
metricStream.on('error', function(err) {
console.log(err);
});
// When EOF, split string on newline
metricStream.on('end', function() {
var eachRow = function(row, callback) {
rows.push(row);
callback();
};
async.forEach(allData.split('\n'), eachRow, function(err) {
if(err) console.log(err);
build(rows, sections, pass, fail);
});
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment