2015-05-19 11:00:06 +00:00
|
|
|
'use strict';
|
2015-03-06 13:08:29 +00:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
// simulate `cat readfile.js | node readfile.js`
|
|
|
|
|
|
|
|
if (process.platform === 'win32') {
|
2015-07-06 03:24:12 +00:00
|
|
|
console.log('1..0 # Skipped: No /dev/stdin on windows.');
|
2015-07-07 15:25:55 +00:00
|
|
|
return;
|
2015-03-06 13:08:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
|
|
|
|
var filename = path.join(common.tmpDir, '/readfile_pipe_large_test.txt');
|
|
|
|
var dataExpected = new Array(1000000).join('a');
|
2015-06-09 18:40:55 +00:00
|
|
|
common.refreshTmpDir();
|
2015-03-06 13:08:29 +00:00
|
|
|
fs.writeFileSync(filename, dataExpected);
|
|
|
|
|
|
|
|
if (process.argv[2] === 'child') {
|
|
|
|
fs.readFile('/dev/stdin', function(er, data) {
|
|
|
|
if (er) throw er;
|
|
|
|
process.stdout.write(data);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var exec = require('child_process').exec;
|
|
|
|
var f = JSON.stringify(__filename);
|
|
|
|
var node = JSON.stringify(process.execPath);
|
|
|
|
var cmd = 'cat ' + filename + ' | ' + node + ' ' + f + ' child';
|
|
|
|
exec(cmd, { maxBuffer: 1000000 }, function(err, stdout, stderr) {
|
|
|
|
if (err) console.error(err);
|
|
|
|
assert(!err, 'it exits normally');
|
|
|
|
assert(stdout === dataExpected, 'it reads the file and outputs it');
|
|
|
|
assert(stderr === '', 'it does not write to stderr');
|
|
|
|
console.log('ok');
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
fs.unlinkSync(filename);
|
|
|
|
});
|