Node.js Readable file stream not getting data -
i'm attempting create readable file stream can read individual bytes from. i'm using code below.
var rs = fs.createreadstream(file).on('open', function() { var buff = rs.read(8); //read first 8 bytes console.log(buff); });
given file existing file of @ least 8 bytes, why getting 'null' output this?
event open
means stream has been initialized, not mean can read stream. have listen either readable
or data
events.
var rs = fs.createreadstream(file); rs.once('readable', function() { var buff = rs.read(8); //read first 8 bytes once console.log(buff.tostring()); });
Comments
Post a Comment