stdinGenerator() doesn't yield an empty line when the first character received is newline.
Following is the fix.
function* stdinGenerator() {
let lineBuff = Buffer.allocUnsafe(0);
while (true) {
const readBuff = Buffer.allocUnsafe(1);
try {
if (readSync(stdinFileDescriptor, readBuff, 0, 1, null) === 0) {
// EOF
break;
}
lineBuff = Buffer.concat([lineBuff, readBuff]);
if (readBuff[0] === NEW_LINE) {
yield lineBuff.toString();
lineBuff = Buffer.allocUnsafe(0);
}
} catch (err) {
if (err.code === 'EAGAIN') {
continue;
}
throw err;
}
}
if (lineBuff.length > 0) {
yield lineBuff.toString();
}
}
stdinGenerator() doesn't yield an empty line when the first character received is newline.
Following is the fix.