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

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

Closed
azasypkin opened this issue Aug 3, 2017 · 4 comments
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. good first issue Issues that are suitable for first-time contributors. stream Issues and PRs related to the stream subsystem.

Comments

@azasypkin
Copy link
Contributor

  • 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

@mscdex mscdex added doc Issues and PRs related to the documentations. stream Issues and PRs related to the stream subsystem. labels Aug 3, 2017
@MylesBorins
Copy link
Contributor

/cc @nodejs/streams @mcollina

@mcollina
Copy link
Member

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

@mcollina mcollina added good first issue Issues that are suitable for first-time contributors. fs Issues and PRs related to the fs subsystem / file system. labels Aug 16, 2017
@azasypkin
Copy link
Contributor Author

@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).

@mcollina
Copy link
Member

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

@refack refack closed this as completed in e96c11c Aug 20, 2017
MylesBorins pushed a commit that referenced this issue Sep 10, 2017
The documentation for `fs.createWriteStream()` references a
`defaultEncoding` as possible options property, but in reality
`encoding` property is expected and properly handled. This fix updates
the documentation to rename the `defaultEncoding` property to
`encoding`.

PR-URL: #14867
Fixes: #14611
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this issue Sep 12, 2017
The documentation for `fs.createWriteStream()` references a
`defaultEncoding` as possible options property, but in reality
`encoding` property is expected and properly handled. This fix updates
the documentation to rename the `defaultEncoding` property to
`encoding`.

PR-URL: #14867
Fixes: #14611
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. good first issue Issues that are suitable for first-time contributors. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants