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

doc: fix about decodeStrings property of stream.Writable #19752

Closed
wants to merge 4 commits into from

Conversation

mandel59
Copy link
Contributor

@mandel59 mandel59 commented Apr 2, 2018

This fixes negation ommitted at 80ea0c5.

Corresponding sentence at 5292a13 (before 80ea0c5):

If you do not explicitly set the decodeStrings option to false, then you can safely ignore the encoding argument, and assume that chunk will always be a Buffer.

Checklist

@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. stream Issues and PRs related to the stream subsystem. labels Apr 2, 2018
@mandel59 mandel59 changed the title doc: fix about decodeStrings property of stream.Writable [WIP]doc: fix about decodeStrings property of stream.Writable Apr 2, 2018
@mandel59
Copy link
Contributor Author

mandel59 commented Apr 2, 2018

I've noticed that the phrase "and chunk will remain the same object that is passed to .write()" is in case where decodeStrings is true, so that part has to rewritten too.

@mandel59
Copy link
Contributor Author

mandel59 commented Apr 2, 2018

I wonder what "the character encoding of the string" is. It should be UTF-16 in JavaScript, shouldn't it?

@mandel59 mandel59 changed the title [WIP]doc: fix about decodeStrings property of stream.Writable doc: fix about decodeStrings property of stream.Writable Apr 2, 2018
@mscdex mscdex added wip Issues and PRs that are still a work in progress. and removed wip Issues and PRs that are still a work in progress. labels Apr 2, 2018
options, then `chunk` will remain the same object that is passed to `.write()`,
and may be a string rather than a Buffer. In that case, the `encoding` argument
will indicate the character encoding of the string. Otherwise, the `encoding`
argument can be safely ignored.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, feel free to mention that it’s always going to be 'buffer' in that case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about object mode streams? I just tried and got 'utf8' as encoding. Is it intended?

@addaleax
Copy link
Member

addaleax commented Apr 2, 2018

I wonder what "the character encoding of the string" is.

It is generally whatever is being passed to .write(), and UTF-8 by default for strings.

It should be UTF-16 in JavaScript, shouldn't it?

JS strings don’t really have a character encoding – the way that JS strings work, it is reasonable for the engine to store them using UTF-16, but that’s transparent to the user and it’s not universally true.

The character encoding in this context is not some intrinsic property of the string; it has to be passed along as separate metadata. For example, process.stdout.write('abc', 'utf8'); means “write the string 'abc', encoded into a sequence of bytes using UTF-8, to stdout”.

@mandel59
Copy link
Contributor Author

mandel59 commented Apr 2, 2018

"The character encoding of the string" actually means "the character encoding which chunk is
intended to be written as", doesn't it? But it would be not the case when encoding is "base64", where it actually means to "decode" from base64.

@addaleax
Copy link
Member

addaleax commented Apr 2, 2018

"The character encoding of the string" actually means "the character encoding which chunk is
intended to be written as", doesn't it?

Yup, exactly that. :)

But it would be not the case when encoding is "base64", where it actually means to "decode" from base64.

Yes, that’s somewhat unfortunate – Node.js puts both character encodings (sequence of characters → seq of bytes) and binary-to-text encodings (seq of bytes → seq of characters) behind the same API, because that happens to work out fine.

So, yeah, you’re right, the API that one would use to encode UTF-8 or UTF-16 in Node.js would be the API that decodes hex and base64. It’s confusing, especially for newbies, and if you have suggestions for improving the documentation on this, that would be really really neat.

@lpinca
Copy link
Member

lpinca commented Apr 4, 2018

object that is passed to `.write()`.
If the `decodeStrings` property is explicitly set to `false` in the constructor
options, then `chunk` will remain the same object that is passed to `.write()`,
and may be a string rather than a Buffer. This is to support implementations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Buffer/Buffer (surround with backticks) ... this should be consistent throughout the doc if it's not already.

@mandel59 mandel59 force-pushed the fix-doc-decodeStrings branch from 626d237 to 0e9e2e2 Compare April 4, 2018 23:33
@BridgeAR
Copy link
Member

BridgeAR commented Apr 9, 2018

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 9, 2018
@BridgeAR
Copy link
Member

BridgeAR commented Apr 9, 2018

Landed in 8788046 🎉

@BridgeAR BridgeAR closed this Apr 9, 2018
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Apr 9, 2018
This fixes negation ommitted in a former commit.
It also simplifies the text in general.

PR-URL: nodejs#19752
Refs: nodejs@80ea0c5
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
targos pushed a commit that referenced this pull request Apr 12, 2018
This fixes negation ommitted in a former commit.
It also simplifies the text in general.

PR-URL: #19752
Refs: 80ea0c5
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. doc Issues and PRs related to the documentations. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants