EN
Node.js - Error: EAGAIN: resource temporarily unavailable, read
1
answers
7
points
Any idea why Node.js throws exception when I try to read process.stdin
using fs.readSync(fd, buffer, offset, length)
?
I thought, if I will pipe input stream it should be working well.
I try to run Node.js as sub-process.
Under Windows all warks great, under Linux I get:
Error: EAGAIN: resource temporarily unavailable, read
at Object.readSync (node:fs:749:3)
at exports.readStream (/opt/shop/utils.js:19:19)
at async /opt/shop/shop/index.js:13:5
What it menas? Is my pipe broken?
1 answer
3
points
EAGAIN
code just means: there is nothing to read now and you should try read later.
Example unification for Window and Unix/Linux:
const fs = require('fs');
// Reads bytes into buffer returning -1 when transmission ended.
//
const readSync = (fd, buffer, offset, length) => {
try {
const result = fs.readSync(fd, buffer, offset, length);
return result === 0 ? -1 : result;
} catch (error) {
if (error.code === 'EAGAIN') { // when there is nothing to read at the current time
return 0;
}
throw error;
}
};
See also
Refrences
0 comments
Add comment