Node.js Readable file stream not getting data
node.js, stream
Solution
Event `open` means that stream has been initialized, it does not mean you can read from the stream. You would have to listen for either `readable` or `data` events.
var rs = fs.createReadStream(file);
rs.once('readable', function() {
var buff = rs.read(8); //Read first 8 bytes only once
console.log(buff.toString());
});
Problem
I'm attempting to create a Readable file stream that I can read individual bytes from. I'm using the code below. ``` var rs = fs.createReadStream(file).on('open', function() { var buff = rs.read(8); //Read first 8 bytes console.log(buff); }); ``` Given that file is an existing file of at least 8 bytes, why am I getting 'null' as the output for this?