Skip to content

fsPromises.readFile ignores encoding option #19286

Description

@Legends
  • Version: v10.0.0-nightly20180309099e621648
  • Platform: Win10 x64
  • Subsystem: ?
var fs = require('fs/promises'); 
fs.readFile(path,"utf8").then((data)=>...

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?

Activity

  1. added
    fsIssues and PRs related to file-system APIs and the fs module.
    promisesIssues and PRs related to ECMAScript promises.
    on Mar 11, 2018
  2. benjamingr commented on Mar 12, 2018

    @benjamingr
    Member

    Looks like a bug to me, fs.readFileSync returns a string for the same call.

  3. benjamingr commented on Mar 12, 2018

    @benjamingr
    Member

    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.promisify on fs.readFile

  4. benjamingr commented on Mar 12, 2018

    @benjamingr
    Member

    Looks like the encoding handling is missing in fs/promises and it is simply ignored https://github.com/nodejs/node/blob/master/lib/fs.js#L403-L405

    https://github.com/nodejs/node/blob/master/lib/fs/promises.js#L132 ignores options passed in.

  5. self-assigned this
    on Mar 12, 2018
  6. benjamingr commented on Mar 12, 2018

    @benjamingr
    Member

    Going to tackle this one

  7. changed the title [-]Question: require('fs/promises')[/-] [+]fsPromises.readFile ignores encoding[/+] on Mar 12, 2018
  8. changed the title [-]fsPromises.readFile ignores encoding[/-] [+]fsPromises.readFile ignores encoding option[/+] on Mar 12, 2018
  9. added a commit that references this issue on Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

confirmed-bugIssues and PRs for confirmed bugs.fsIssues and PRs related to file-system APIs and the fs module.promisesIssues and PRs related to ECMAScript promises.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions