Created
September 12, 2011 21:49
-
-
Save mikekunze/1212568 to your computer and use it in GitHub Desktop.
beadChips async init function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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