Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs/promises: ensure options.flag is defaulted to 'r' in readFile #20268

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fs: return string on empty fs.promises.readFile() when encoding provided
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.
  • Loading branch information
bdistin committed May 28, 2018
commit 543f29729872befed736ce758fc1d3fff829dadc
2 changes: 1 addition & 1 deletion lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async function readFileHandle(filehandle, options) {
}

if (size === 0)
return Buffer.alloc(0);
return options.encoding ? '' : Buffer.alloc(0);

if (size > kMaxLength)
throw new ERR_FS_FILE_TOO_LARGE(size);
Expand Down