Commit 44ef458
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: #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>1 parent 04af697 commit 44ef458Copy full SHA for 44ef458
File tree
Expand file treeCollapse file tree
3 files changed
+26
-2
lines changedOpen diff view settings
Filter options
- lib/internal/fs
- test/parallel
Expand file treeCollapse file tree
3 files changed
+26
-2
lines changedOpen diff view settings
Collapse file
lib/internal/fs/promises.js
Copy file name to clipboardExpand all lines: lib/internal/fs/promises.js+3-2Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
137 | 137 | |
138 | 138 | |
139 | 139 | |
140 | | - |
| 140 | + |
141 | 141 | |
142 | 142 | |
143 | 143 | |
| ||
459 | 459 | |
460 | 460 | |
461 | 461 | |
| 462 | + |
462 | 463 | |
463 | 464 | |
464 | 465 | |
465 | 466 | |
466 | | - |
| 467 | + |
467 | 468 | |
468 | 469 | |
469 | 470 | |
|
Collapse file
test/parallel/test-fs-promises-readfile-empty.js
Copy file name to clipboard+19Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
Collapse file
test/parallel/test-fs-readfile-empty.js
Copy file name to clipboardExpand all lines: test/parallel/test-fs-readfile-empty.js+4Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
38 | 38 | |
39 | 39 | |
40 | 40 | |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
41 | 45 | |
42 | 46 | |
0 commit comments