-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: keep fs.promises.readFile read until EOF is reached
PR-URL: #52178 Fixes: #52155 Reviewed-By: Chengzhong Wu <[email protected]>
- Loading branch information
1 parent
f9688ab
commit 51e6edc
Showing
2 changed files
with
54 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
if (common.isWindows || common.isAIX || common.isIBMi) | ||
common.skip(`No /dev/stdin on ${process.platform}.`); | ||
|
||
const assert = require('assert'); | ||
const fs = require('fs/promises'); | ||
const childType = ['child-encoding', 'child-non-encoding']; | ||
|
||
if (process.argv[2] === childType[0]) { | ||
fs.readFile('/dev/stdin', 'utf8').then((data) => { | ||
process.stdout.write(data); | ||
}); | ||
return; | ||
} else if (process.argv[2] === childType[1]) { | ||
fs.readFile('/dev/stdin').then((data) => { | ||
process.stdout.write(data); | ||
}); | ||
return; | ||
} | ||
|
||
const data1 = 'Hello'; | ||
const data2 = 'World'; | ||
const expected = `${data1}\n${data2}\n`; | ||
|
||
const exec = require('child_process').exec; | ||
const f = JSON.stringify(__filename); | ||
const node = JSON.stringify(process.execPath); | ||
|
||
function test(child) { | ||
const cmd = `(echo ${data1}; sleep 0.5; echo ${data2}) | ${node} ${f} ${child}`; | ||
exec(cmd, common.mustSucceed((stdout, stderr) => { | ||
assert.strictEqual( | ||
stdout, | ||
expected, | ||
`expected to read(${child === childType[0] ? 'with' : 'without'} encoding): '${expected}' but got: '${stdout}'`); | ||
assert.strictEqual( | ||
stderr, | ||
'', | ||
`expected not to read anything from stderr but got: '${stderr}'`); | ||
})); | ||
} | ||
|
||
test(childType[0]); | ||
test(childType[1]); |