Skip to content

Documentation should mention encoding instead of defaultEncoding as options property for fs.createWriteStream #14611

Description

@azasypkin
  • Version: 6.11.1
  • Platform: Linux 4.12.3-1-ARCH
  • Subsystem: fs

Documentation says that defaultEncoding is the right options property for fs.createWriteStream. But if we look into source code [1] options are directly passed to WriteStream that expects options.encoding [2]. At the same time options are passed to Writable->WritableState [3] that expects options.defaultEncoding instead [4].

For example this inconsistency reveals when you pass "wrong" encoding. Both following examples throw TypeError: Unknown encoding: unknown:

fs.createWriteStream('....', 'unknown');

and

fs.createWriteStream('....', { encoding: 'unknown' });

But the following example doesn't throw anything:

fs.createWriteStream('....', { defaultEncoding: 'unknown' });

I see there was a similar issue a while ago: nodejs/node-v0.x-archive#7710. So at least it's confusing.

[1] https://github.com/nodejs/node/blob/v6.x/lib/fs.js#L2059
[2] https://github.com/nodejs/node/blob/v6.x/lib/fs.js#L2100
[3] https://github.com/nodejs/node/blob/v6.x/lib/fs.js#L2077
[4] https://github.com/nodejs/node/blob/v6.x/lib/_stream_writable.js#L64

Activity

  1. added
    docIssues and PRs related to Node.js documentation.
    streamIssues and PRs related to Node.js streams.
    on Aug 3, 2017
  2. MylesBorins commented on Aug 11, 2017

    @MylesBorins
    Contributor

    /cc @nodejs/streams @mcollina

  3. mcollina commented on Aug 16, 2017

    @mcollina
    SponsorMember

    I would say we should update the docs to use 'encoding' instead. @azasypkin would you like to send a PR?

  4. added
    good first issueIssues that are suitable for first-time contributors.
    fsIssues and PRs related to file-system APIs and the fs module.
    on Aug 16, 2017
  5. azasypkin commented on Aug 16, 2017

    @azasypkin
    ContributorAuthor

    @azasypkin would you like to send a PR?

    Sure, but will go through CONTRIBUTING.md first. Should the fix go to master only or PRs for 6/7/8 will be needed too?

    And I'm going to update TS type definitions too (I see it has been noticed already DefinitelyTyped/DefinitelyTyped#14981).

  6. mcollina commented on Aug 16, 2017

    @mcollina
    SponsorMember

    the fix will go to master, and then we will backport to 8 and 6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.fsIssues and PRs related to file-system APIs and the fs module.good first issueIssues that are suitable for first-time contributors.streamIssues and PRs related to Node.js streams.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions