I'm using lazy
and fs
to read a file line-by-line (reference):
Lazy = require('lazy');
fs = require('fs');
lazy = new Lazy(fs.createReadStream(filename, {
encoding: 'utf8'
}));
lazy.lines.forEach(function(line) {
line = String(line);
// more stuff...
}
The weird thing is, when an empty line is read, String(line)
results in the string 0
. This is a problem because I can't find a way to distinguish whether the 0
is a result of an empty line, or if the line actually contains a single character 0
.
Why is it so? And how to solve this problem?