-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stdin fd doesn't works when it's a pipe #15497
Comments
Code for posterity: var fs = require('fs')
var fd = process.stdin.fd;
var length = fs.fstatSync(fd).size;
var buffer = new Buffer(length);
var bytesRead = fs.readSync(fd, buffer, 0, length, 0);
var input = buffer.toString('utf8', 0, bytesRead);
console.log(input); |
Oops, it's a mistake. it doesn't works on macOS too. The difference is that it reporting an error only on macOS
|
This works fine on macOS. var fs = require('fs')
var fd = process.stdin.fd;
var length = fs.fstatSync(fd).size;
var buffer = new Buffer(length);
var bytesRead = fs.readSync(fd, buffer, 0, length, null);
var input = buffer.toString('utf8', 0, bytesRead);
console.log(input); - var bytesRead = fs.readSync(fd, buffer, 0, length, 0);
+ var bytesRead = fs.readSync(fd, buffer, 0, length, null); |
This line doesn't make sense if See http://yarchive.net/comp/linux/stat_size.html for some background. I'll close this out. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fs apis like fstatSync or readSync don't read state or data fed through pipe.
Reproducible code
https://wandbox.org/permlink/zU1uUULheUpxmgfN
But with stream api, it works properly.
https://wandbox.org/permlink/XW7rOuJQCCyqCFPX
This problem occurred only on linux as long as I tested, not on macOS.
The text was updated successfully, but these errors were encountered: