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

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