I am attempting to view a log with a program called 'logger'. When I run node logger
I get the following error:
<Buffer 66 72 75 69 74 69 73 68 79 0a>
The 'logger' program file looks as follows:
var fs = require('fs');
var file = fs.createReadStream("veg.log");
file.on('readable', function() {
var stream = null;
while(null !== (stream = file.read())) {
stream.toString();
console.log(stream);
}
});
Does anyone have an idea what's causing the error? The log file is just plain text. Why is this causing an error with my buffer and how do I find out which buffer it is and what's causing it to be incorrectly accessed?
The canonical procedure is to use a buffer to collect chunks of data by listening to
on('data')
events. When the stream is finished, theon('end')
event will be emitted, and then you can do something with the buffer.This code should do what you need:
You need to specify a buffer option for the
createReadStream
function. Like so: