-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,25 @@ const { | |
Symbol, | ||
SymbolIterator | ||
} = primordials; | ||
const { Buffer } = require('buffer'); | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. nit, Not sure of the purpose here, but wouldn't There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
...opts, | ||
read() { | ||
this.push(iterable); | ||
this.push(null); | ||
} | ||
}); | ||
} | ||
|
||
if (iterable && iterable[Symbol.asyncIterator]) | ||
iterator = iterable[Symbol.asyncIterator](); | ||
else if (iterable && iterable[SymbolIterator]) | ||
|
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