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

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -