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
|
|
|
|
|
|
|
// simulate `cat readfile.js | node readfile.js`
|
|
|
|
|
2017-07-16 07:07:33 +00:00
|
|
|
if (common.isWindows || common.isAIX)
|
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');
|
|
|
|
const path = require('path');
|
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;
|
|
|
|
}
|
|
|
|
|
2016-09-29 01:55:59 +00:00
|
|
|
const filename = path.join(common.tmpDir, '/readfile_pipe_large_test.txt');
|
2017-01-30 08:57:49 +00:00
|
|
|
const dataExpected = 'a'.repeat(999999);
|
2015-07-29 00:30:28 +00:00
|
|
|
common.refreshTmpDir();
|
|
|
|
fs.writeFileSync(filename, dataExpected);
|
|
|
|
|
2016-09-29 01:55:59 +00:00
|
|
|
const exec = require('child_process').exec;
|
|
|
|
const f = JSON.stringify(__filename);
|
|
|
|
const node = JSON.stringify(process.execPath);
|
|
|
|
const cmd = `cat ${filename} | ${node} ${f} child`;
|
2015-03-06 13:08:29 +00:00
|
|
|
exec(cmd, { maxBuffer: 1000000 }, function(err, stdout, stderr) {
|
2016-12-30 15:54:01 +00:00
|
|
|
assert.ifError(err);
|
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');
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
fs.unlinkSync(filename);
|
|
|
|
});
|