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-promises-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-promises-readfile-empty.js')
-rw-r--r-- | test/parallel/test-fs-promises-readfile-empty.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/parallel/test-fs-promises-readfile-empty.js b/test/parallel/test-fs-promises-readfile-empty.js new file mode 100644 index 0000000000..24c17655c6 --- /dev/null +++ b/test/parallel/test-fs-promises-readfile-empty.js @@ -0,0 +1,19 @@ +'use strict'; +const common = require('../common'); + +const assert = require('assert'); +const { promises: fs } = require('fs'); +const fixtures = require('../common/fixtures'); + +const fn = fixtures.path('empty.txt'); + +common.crashOnUnhandledRejection(); + +fs.readFile(fn) + .then(assert.ok); + +fs.readFile(fn, 'utf8') + .then(assert.strictEqual.bind(this, '')); + +fs.readFile(fn, { encoding: 'utf8' }) + .then(assert.strictEqual.bind(this, '')); |