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 trivial mistakes in stream document. #10411

Closed
wants to merge 2 commits into from

Conversation

fmy
Copy link
Contributor

@fmy fmy commented Dec 22, 2016

Checklist
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

doc

Description of change

1st commit:
In stream.Writable, when decodeStrings option is false, the chunk _write() function received is not always be Buffer, it depends types of the sources.

const {Writable} = require('stream');
class MyWritable extends Writable {
  _write(chunk, enc, cb) {
    console.log(chunk);
    console.log('typeof chunk : ' + typeof chunk);
    cb();
  }
}

const w = new MyWritable({decodeStrings: false});
w.write('abc');
w.write(Buffer.from('abc'));

// => abc
// => typeof chunk : string
// => <Buffer 61 62 63>
// => typeof chunk : object

2nd commit:
This is a trivial fix, 'unexpected' fits this context.

@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. stream Issues and PRs related to the stream subsystem. lts-watch-v6.x labels Dec 22, 2016
@fmy fmy changed the title doc: fix a trivial mistake in stream document. doc: fix trivial mistakes in stream document. Dec 22, 2016
the `encoding` argument can be safely ignored, and `chunk` will always be a
`Buffer`.
the `encoding` argument can be safely ignored, and `chunk` will remain the same
type from the source.
Copy link
Contributor

Choose a reason for hiding this comment

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

How can one tell what the type is? I thought these were always Buffers lol.

Do you mean it is different for Object Mode?

Copy link
Contributor Author

@fmy fmy Dec 22, 2016

Choose a reason for hiding this comment

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

When decodeStrings is true, string is converted into Buffer here.
https://github.com/nodejs/node/blob/v6.9.3-proposal/lib/_stream_writable.js#L285-L288
Of course Buffer is still Buffer. So the chunk always be a Buffer.

When decodeStrings is false, there is no conversion before _write() received it.
So, string keeps string, not always be Buffer.
Please see upper sample codes.

Copy link
Member

Choose a reason for hiding this comment

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

@fmy you are right. I would phrase that differently thought, because Writable  can be used also without pipe(). How about:

will remain the same object that is passed to .write().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will remain the same object that is passed to .write().

@mcollina thanks! i will change words.

@italoacasas
Copy link
Contributor

@nodejs/streams

the `encoding` argument can be safely ignored, and `chunk` will always be a
`Buffer`.
the `encoding` argument can be safely ignored, and `chunk` will remain the same
type from the source.
Copy link
Member

Choose a reason for hiding this comment

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

@fmy you are right. I would phrase that differently thought, because Writable  can be used also without pipe(). How about:

will remain the same object that is passed to .write().

fmy added 2 commits December 23, 2016 16:51
When decodeStrings is false and given data is string, _write() function
receives the string data not `Buffer`.
In this context, 'expected' looks strange word.
@fmy
Copy link
Contributor Author

fmy commented Dec 23, 2016

I changed some words.
@mcollina Thanks for your review.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

jasnell pushed a commit that referenced this pull request Dec 27, 2016
When decodeStrings is false and given data is string, _write() function
receives the string data not `Buffer`.

PR-URL: #10411
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@jasnell
Copy link
Member

jasnell commented Dec 27, 2016

Landed in 37d6052

@jasnell jasnell closed this Dec 27, 2016
@fmy fmy deleted the doc/stream-decodeStrings branch December 28, 2016 02:33
evanlucas pushed a commit that referenced this pull request Jan 3, 2017
When decodeStrings is false and given data is string, _write() function
receives the string data not `Buffer`.

PR-URL: #10411
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
evanlucas pushed a commit that referenced this pull request Jan 4, 2017
When decodeStrings is false and given data is string, _write() function
receives the string data not `Buffer`.

PR-URL: #10411
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jan 23, 2017
When decodeStrings is false and given data is string, _write() function
receives the string data not `Buffer`.

PR-URL: #10411
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jan 24, 2017
When decodeStrings is false and given data is string, _write() function
receives the string data not `Buffer`.

PR-URL: #10411
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Jan 24, 2017
MylesBorins pushed a commit that referenced this pull request Jan 31, 2017
When decodeStrings is false and given data is string, _write() function
receives the string data not `Buffer`.

PR-URL: #10411
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
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. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants