2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-09-29 03:55:59 +02:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const path = require('path');
|
2015-03-06 14:08:29 +01:00
|
|
|
|
|
|
|
// simulate `cat readfile.js | node readfile.js`
|
|
|
|
|
2015-08-12 17:53:33 +02:00
|
|
|
if (common.isWindows || common.isAix) {
|
2016-09-29 03:30:32 +02:00
|
|
|
common.skip(`No /dev/stdin on ${process.platform}.`);
|
2015-07-07 17:25:55 +02:00
|
|
|
return;
|
2015-03-06 14:08:29 +01:00
|
|
|
}
|
|
|
|
|
2016-09-29 03:55:59 +02:00
|
|
|
const fs = require('fs');
|
2015-03-06 14:08:29 +01:00
|
|
|
|
|
|
|
if (process.argv[2] === 'child') {
|
|
|
|
fs.readFile('/dev/stdin', function(er, data) {
|
|
|
|
if (er) throw er;
|
|
|
|
process.stdout.write(data);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-29 03:55:59 +02:00
|
|
|
const filename = path.join(common.tmpDir, '/readfile_pipe_large_test.txt');
|
|
|
|
const dataExpected = new Array(1000000).join('a');
|
2015-07-29 02:30:28 +02:00
|
|
|
common.refreshTmpDir();
|
|
|
|
fs.writeFileSync(filename, dataExpected);
|
|
|
|
|
2016-09-29 03:55:59 +02: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 14:08:29 +01:00
|
|
|
exec(cmd, { maxBuffer: 1000000 }, function(err, stdout, stderr) {
|
|
|
|
if (err) console.error(err);
|
|
|
|
assert(!err, 'it exits normally');
|
2016-09-17 12:32:33 +02:00
|
|
|
assert.strictEqual(stdout, dataExpected, 'it reads the file and outputs it');
|
|
|
|
assert.strictEqual(stderr, '', 'it does not write to stderr');
|
2015-03-06 14:08:29 +01:00
|
|
|
console.log('ok');
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
fs.unlinkSync(filename);
|
|
|
|
});
|