2015-05-19 11:00:06 +00:00
|
|
|
'use strict';
|
2016-09-29 01:55:59 +00:00
|
|
|
const common = require('../common');
|
2015-03-06 13:08:29 +00:00
|
|
|
|
2019-01-21 00:22:27 +00:00
|
|
|
// Simulate `cat readfile.js | node readfile.js`
|
2015-03-06 13:08:29 +00:00
|
|
|
|
2023-09-28 12:51:44 +00:00
|
|
|
if (common.isWindows || common.isAIX || common.isIBMi)
|
2016-09-29 01:30:32 +00:00
|
|
|
common.skip(`No /dev/stdin on ${process.platform}.`);
|
2015-03-06 13:08:29 +00:00
|
|
|
|
2017-06-30 23:29:09 +00:00
|
|
|
const assert = require('assert');
|
2016-09-29 01:55:59 +00:00
|
|
|
const fs = require('fs');
|
2015-03-06 13:08:29 +00:00
|
|
|
|
|
|
|
if (process.argv[2] === 'child') {
|
|
|
|
fs.readFile('/dev/stdin', function(er, data) {
|
2016-12-30 15:54:01 +00:00
|
|
|
assert.ifError(er);
|
2015-03-06 13:08:29 +00:00
|
|
|
process.stdout.write(data);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-25 06:38:11 +00:00
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
|
2023-08-15 13:45:14 +00:00
|
|
|
const filename = tmpdir.resolve('readfile_pipe_large_test.txt');
|
2017-01-30 08:57:49 +00:00
|
|
|
const dataExpected = 'a'.repeat(999999);
|
2017-12-25 06:38:11 +00:00
|
|
|
tmpdir.refresh();
|
2015-07-29 00:30:28 +00:00
|
|
|
fs.writeFileSync(filename, dataExpected);
|
|
|
|
|
2016-09-29 01:55:59 +00:00
|
|
|
const exec = require('child_process').exec;
|
2024-09-29 20:44:52 +00:00
|
|
|
const [cmd, opts] = common.escapePOSIXShell`"${process.execPath}" "${__filename}" child < "${filename}"`;
|
|
|
|
exec(cmd, { ...opts, maxBuffer: 1000000 }, common.mustSucceed((stdout, stderr) => {
|
2017-11-06 17:06:03 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
stdout,
|
|
|
|
dataExpected,
|
|
|
|
`expect it reads the file and outputs 999999 'a' but got : ${stdout}`
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
stderr,
|
|
|
|
'',
|
|
|
|
`expect that it does not write to stderr, but got : ${stderr}`
|
|
|
|
);
|
2015-03-06 13:08:29 +00:00
|
|
|
console.log('ok');
|
2019-04-28 08:56:57 +00:00
|
|
|
}));
|