-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
stream: do not chunk strings and Buffer in Readable.from. #30912
Conversation
|
||
const { | ||
ERR_INVALID_ARG_TYPE | ||
} = require('internal/errors').codes; | ||
|
||
function from(Readable, iterable, opts) { | ||
let iterator; | ||
if (typeof iterable === 'string' || iterable instanceof Buffer) { | ||
return new Readable({ | ||
objectMode: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, Not sure of the purpose here, but wouldn't objectMode: false
make more sense here as a default? Or is that breaking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep it consistent with the rest. Also, it would change the encoding, so possibly it's not a good idea.
This does change behaviour when a buffer is passed, is that intentional? |
Yes, instead of emitting one byte at a time, we will push through the full chunk. This will remove a lot of overhead when using this API. |
@mcollina yes, but instead of emitting numbers, it now emits a Buffer |
Ouch. I would consider this a bug :/. |
|
||
const { | ||
ERR_INVALID_ARG_TYPE | ||
} = require('internal/errors').codes; | ||
|
||
function from(Readable, iterable, opts) { | ||
let iterator; | ||
if (typeof iterable === 'string' || iterable instanceof Buffer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check for Stream._isUint8Array
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would only be okay if we turn off object mode, I think
I would agree, but could you document that |
378e505
to
019d0d0
Compare
019d0d0
to
4dbdd43
Compare
This comment has been minimized.
This comment has been minimized.
Landed in f8018f2 |
PR-URL: #30912 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
PR-URL: #30912 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
PR-URL: #30912 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
PR-URL: #30912 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
This PR makes
Readable.from()
to not iterate over strings and buffers to avoid unnecessary overhead.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes