Uh oh!
There was an error while loading. Please reload this page.
stream: convert string to Buffer when calling unshift(<string>) - #27194
Conversation
Trott
commented
Apr 11, 2019
Can you add a test for this? |
marcosc90
commented
Apr 12, 2019
@Trott added multiple cases, if something is missing or needs to be changed let me know. |
Trott
commented
Apr 12, 2019
Thanks! Only other thing to add that I can see is the R: @nodejs/streams |
mcollina
commented
Apr 12, 2019
I think this is semver-minor as it's adding a new parameter. CI: https://ci.nodejs.org/job/node-test-pull-request/22398/ |
nodejs-github-bot
commented
Apr 12, 2019
addaleax
left a comment
There was a problem hiding this comment.
Can you also add a test for how this interacts with .setEncoding()?
marcosc90
commented
Apr 12, 2019
I'll submit one in a few. Forgot about that scenario, thanks! |
@addaleax When doing that test, I remember that when I don't think this PR should change that, I'm not even sure if it should be saved as a Buffer in that case, even though it's called So I can test that the behaviour is unchanged, meaning that they're saved as string, and that Is that ok? |
There is one change left, but would like some feedback. When But in order to keep the same behaviour, I have to convert the pushed string, to the encoding defined by Because the string must be saved in BufferList in the same encoding as Thoughts? Maybe someone has another alternative. |
Uh oh!
There was an error while loading. Please reload this page.
marcosc90
commented
Apr 24, 2019
Is there something else that should be added/changed? |
mcollina
left a comment
There was a problem hiding this comment.
I’ve left some notes related to the tests. I think we should remove the usage of private API as much as possible - the majority of this feature should be testable without it.
There was a problem hiding this comment.
This test can be rewritten without using internals, it should consume the stream and check that the chunks comes out in order.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
This can be tested by consuming the stream and verifying that the data comes out in order.
This comment has been minimized.
This comment has been minimized.
nodejs-github-bot
commented
Jun 2, 2019
`readable.unshift` can take a string as an argument, but that string wasn't being converted to a Buffer, which caused a <TypeError: Argument must be a buffer> in some cases. Also if a string was passed, that string was coerced to utf8 encoding. A second optional argument `encoding` was added to `unshift` to fix the encoding issue. Fixes: #27192 PR-URL: #27194 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Trott
commented
Jun 2, 2019
Landed in df339bc |
`readable.unshift` can take a string as an argument, but that string wasn't being converted to a Buffer, which caused a <TypeError: Argument must be a buffer> in some cases. Also if a string was passed, that string was coerced to utf8 encoding. A second optional argument `encoding` was added to `unshift` to fix the encoding issue. Fixes: #27192 PR-URL: #27194 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Notable changes: * doc: * The JSON variant of the API documentation is no longer experimental (Rich Trott) #27842. * esm: * JSON module support is always enabled under `--experimental-modules`. The `--experimental-json-modules` flag has been removed (Myles Borins) #27752. * http,http2: * A new flag has been added for overriding the default HTTP server socket timeout (which is two minutes). Pass `--http-server-default-timeout=milliseconds` or `--http-server-default-timeout=0` to respectively change or disable the timeout. Starting with Node.js 13.0.0, the timeout will be disabled by default (Ali Ijaz Sheikh) #27704. * inspector: * Added an experimental `--heap-prof` flag to start the V8 heap profiler on startup and write the heap profile to disk before exit (Joyee Cheung) #27596. * stream: * The `readable.unshift()` method now correctly converts strings to buffers. Additionally, a new optional argument is accepted to specify the string's encoding, such as `'utf8'` or `'ascii'` (Marcos Casagrande) #27194. * v8: * The object returned by `v8.getHeapStatistics()` has two new properties: `number_of_native_contexts` and `number_of_detached_contexts` (Yuriy Vasiyarov) #27933. PR-URL: #28040
Notable changes: * doc: * The JSON variant of the API documentation is no longer experimental (Rich Trott) nodejs#27842. * esm: * JSON module support is always enabled under `--experimental-modules`. The `--experimental-json-modules` flag has been removed (Myles Borins) nodejs#27752. * http,http2: * A new flag has been added for overriding the default HTTP server socket timeout (which is two minutes). Pass `--http-server-default-timeout=milliseconds` or `--http-server-default-timeout=0` to respectively change or disable the timeout. Starting with Node.js 13.0.0, the timeout will be disabled by default (Ali Ijaz Sheikh) nodejs#27704. * inspector: * Added an experimental `--heap-prof` flag to start the V8 heap profiler on startup and write the heap profile to disk before exit (Joyee Cheung) nodejs#27596. * stream: * The `readable.unshift()` method now correctly converts strings to buffers. Additionally, a new optional argument is accepted to specify the string's encoding, such as `'utf8'` or `'ascii'` (Marcos Casagrande) nodejs#27194. * v8: * The object returned by `v8.getHeapStatistics()` has two new properties: `number_of_native_contexts` and `number_of_detached_contexts` (Yuriy Vasiyarov) nodejs#27933. PR-URL: nodejs#28040
BethGriggs
commented
Sep 3, 2019
Should this land on v10.x? //cc @mcollina |
mcollina
commented
Sep 4, 2019
Yes please! |
readable.unshiftcan take a string as an argument, but thatstring wasn't being converted to a Buffer, which caused a
TypeError: Argument must be a bufferin some cases.A second optional argument
encodingwas added tounshifttoprevent all strings being coerced to utf8.
Fixes: #27192
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesA documentation change will be needed, for the
encodingargument, but wanted to submit the PR first to see if it will get approved. I will also make a few tests for this if everything is okay.