I get flacky results when trying to read small files from my hard drive. Sometimes, when access to my harddrive is slow, I get the whole content of the small files. Other times, when content was cached by the OS, the Stream sends "data" events before my code gets to hook into them.
Here is the function I'm using to get the content:
{{{
loads file contents into a string
loadVFSFile = (path, _callback) ->
async.waterfall([
(callback) -> vfs.readfile(path, {encoding:'utf8'}, callback),
(meta, callback) ->
data = '';
meta.stream.on("data", (item) ->
data += item;
)
meta.stream.on("end", () ->
callback(null, data);
)
return;
], (err, data) ->
console.log(err, data);
_callback(err, data);
);
}}}
if I don't use async.waterfall then it works much better but it seems that I don't get any guaranty that it will always work...