I have a function called ReadBinaryData() which I would like to create a Read Stream to read binary data and return the binary data back to the calling function via a callback. It seems you can do this w/ Node a few different ways and I have read conflicting info on how to do it. I think I should be using the Buffer object, but not really sure how. I have the following, but it does not seem to be working correctly. Any suggestions ?
function ReadBinaryData(successCallback){
var streamHandle = fs.createReadStream("PATH TO FILE", {encoding: 'binary'});
var contentRead = '';
streamHandle.addListener('data', function(data) {
contentRead += data;
});
streamHandle.addListener('end', function(data) {
successCallback(contentRead);
});
};