Uh oh!
There was an error while loading. Please reload this page.
fs/promises: ensure options.flag is defaulted to 'r' in readFile - #20268
fs/promises: ensure options.flag is defaulted to 'r' in readFile#20268bdistin wants to merge 4 commits into
Conversation
Trott
commented
Apr 24, 2018
@nodejs/fs |
76a8dbb to
58b874dCompareronkorving
commented
Apr 25, 2018
I'm curious if the behavior of |
There was a problem hiding this comment.
This will actually manipulate the passed in options because getOptions does not copy the options object.
Please do:
if(options.flag==null){options=copyObject(options);options.flag='r';}BridgeAR
commented
Apr 25, 2018
@ronkorving you are right in a way: the |
58b874d to
c64b578Comparebdistin
commented
Apr 29, 2018
No longer manipulates the passed in options. Since options.flag is not needed in readFileHandle(), copied the existing style from writeFile() instead of null check + copyObject(). |
apapirovski
commented
May 3, 2018
@nodejs/fs Please have a look at this PR. |
bdistin
commented
May 9, 2018
I see that the fs/promises API has been moved to fs.promises, causing conflicts in this pr. Should I resolve those conflicts? (This is my first pr to Node, so I am still a bit unsure of the processes expected.) |
trivikr
commented
May 9, 2018
3e0d004 to
f5a462fCompareWhen 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 consistently with fs.readFile().bdistin
commented
May 9, 2018
Also given the changes of the fs/promises paradigm, should the pr/commit be named just |
vsemozhetbyt
commented
May 9, 2018
bdistin
commented
May 14, 2018
Is there anything more I need to do? I can't explain how the Windows 2016 binary tests fail, and can't see how that would be related to the changes made in this pr. If this is something I need to fix, can anyone shed light on what changes I might need to make? |
bzoz
commented
May 14, 2018
Windows CI rerun: https://ci.nodejs.org/job/node-test-commit-windows-fanned/17969/ |
bdistin
commented
May 16, 2018
So that CI seemed to have passed, but the checks weren't updated on this pr. Does that mean this is good to go? |
bdistin
commented
May 26, 2018
bump? @nodejs/fs ?? |
joyeecheung
left a comment
There was a problem hiding this comment.
I would've expected that getOptions should extend fields of the options if they are not present..but the current fix works as well.
joyeecheung
commented
May 26, 2018
| const { promises: fs } = require('fs'); | ||
| const fixtures = require('../common/fixtures'); | ||
| const fn = fixtures.path('empty.txt'); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
fail on unhandled rejection
joyeecheung
commented
May 27, 2018
common was required, but not assigned to common in order for the requested change to work.
joyeecheung
commented
May 27, 2018
It seems with the test fixes, the tests have uncovered another bug: https://github.com/nodejs/node/blob/master/lib/internal/fs/promises.js#L140-L141 How should I handle that bug? Should I increase the scope of this pr to fix that bug as well? |
| .then(assert.ok); | ||
| fs.readFile(fn, 'utf8') | ||
| .then(assert.strictEqual.bind(this, '')); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
fs: return string on empty fs.promises.readfile when encoding provided fs.promises.readfile() would provide a buffer whenever an empty file is read, when it should have returned an empty string when encoding is provided.
BridgeAR
commented
May 29, 2018
BridgeAR
commented
May 30, 2018
Landed in 2cd3e61 🎉 |
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: nodejs#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>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: #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>
When passing
{}or{ encoding: 'utf8' }as options to readFile, theflag is not defaulted to 'r' unlike normal fs. This fix makes
(fs/promises).readFile() act consistently with fs.readFile().
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes