diff options
author | Unknown <bdistin@gmail.com> | 2018-05-09 11:48:30 -0500 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-05-30 18:41:19 +0200 |
commit | 2cd3e61b2f222c1e9e396dce6310203fdd960143 (patch) | |
tree | 084d7285580baebb5e3999ef1fe4cf4db6f94c0f /test/parallel/test-fs-readfile-empty.js | |
parent | 72ccafdd1084d9dfec8be91daef58e48a6b6368e (diff) | |
download | android-node-v8-2cd3e61b2f222c1e9e396dce6310203fdd960143.tar.gz android-node-v8-2cd3e61b2f222c1e9e396dce6310203fdd960143.tar.bz2 android-node-v8-2cd3e61b2f222c1e9e396dce6310203fdd960143.zip |
fs: ensure options.flag defaults to 'r' in readFile
When passing {} or { encoding: 'utf8' } as options to readFile, the
flag is not defaulted to 'r' unlike normal fs. This fix makes
fs.promises.readFile() act consistent with fs.readFile().
It also fixes another issue with fs.promises.readfile() where it
returned a Buffer instead of an empty string when encoding is provided.
PR-URL: https://github.com/nodejs/node/pull/20268
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ron Korving <ron@ronkorving.nl>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/parallel/test-fs-readfile-empty.js')
-rw-r--r-- | test/parallel/test-fs-readfile-empty.js | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/test/parallel/test-fs-readfile-empty.js b/test/parallel/test-fs-readfile-empty.js index 21f99fc6be..36eccfb116 100644 --- a/test/parallel/test-fs-readfile-empty.js +++ b/test/parallel/test-fs-readfile-empty.js @@ -38,5 +38,9 @@ fs.readFile(fn, 'utf8', function(err, data) { assert.strictEqual('', data); }); +fs.readFile(fn, { encoding: 'utf8' }, function(err, data) { + assert.strictEqual('', data); +}); + assert.ok(fs.readFileSync(fn)); assert.strictEqual('', fs.readFileSync(fn, 'utf8')); |