Repository navigation
fsPromises.readFile ignores encoding option #19286
Copy link
Copy link
Closed
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.fsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.promisesIssues and PRs related to ECMAScript promises.Issues and PRs related to ECMAScript promises.
Description
Activity
- addedfsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.promisesIssues and PRs related to ECMAScript promises.Issues and PRs related to ECMAScript promises.
on Mar 11, 2018 Looks like a bug to me,
fs.readFileSyncreturns a string for the same call.Can reproduce locally
> await fsPromises.readFile('v8_build_config.json', 'utf-8') <Buffer 7b 22 76 38 5f 74 61 72 67 65 74 5f 63 70 75 22 3a 20 22 78 36 34 22 2c 20 22 69 73 5f 63 66 69 22 3a 20 66 61 6c 73 65 2c 20 22 74 61 72 67 65 74 5f ... > > fs.readFileSync('v8_build_config.json', 'utf-8') '{"v8_target_cpu": "x64", "is_cfi": false, "target_cpu": "x64", "is_ubsan_vptr": false, "is_gcov_coverage": false, "dcheck_always_on": false, "is_component_build": false, "is_asan": false, "is_debug": false, "v8_enable_i18n_support": true, "is_msan": false, "is_tsan": false, "v8_use_snapshot": true, "v8_enable_verify_predictable": false}'Note this works correctly when calling
util.promisifyonfs.readFile- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Mar 12, 2018 Looks like the encoding handling is missing in
fs/promisesand it is simply ignored https://github.com/nodejs/node/blob/master/lib/fs.js#L403-L405https://github.com/nodejs/node/blob/master/lib/fs/promises.js#L132 ignores
optionspassed in.Going to tackle this one
Reacted by jpenney1- changed the title
[-]Question: require('fs/promises')[/-][+]fsPromises.readFile ignores encoding[/+]on Mar 12, 2018 - changed the title
[-]fsPromises.readFile ignores encoding[/-][+]fsPromises.readFile ignores encoding option[/+]on Mar 12, 2018
Metadata
Metadata
Assignees
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.fsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.promisesIssues and PRs related to ECMAScript promises.Issues and PRs related to ECMAScript promises.
data will be of type string, when specifying the encoding in the method call, but with the latest version (v10.0.0-nightly20180309099e621648) I have to
data.toString("utf8")again, to get the result as string.By design?