-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
decodeStrings
option for Writable streams doesn't decode incoming data to Strings
#25464
Comments
That’s because we’re stuck with the wrong option name for backwards compatibility, but we can adjust its documentation. 😕 Would you like to open a PR against this repo to improve the documentation along the lines of your suggestions?
I’d also like it if we could have an equivalent of readable stream’s |
I certainly make a PR for a doc change. I can't commit to helping out with #7425, I don't know about node performance to improve it or argue why a change to make devs lives easier is worth a performance hit. That branch looks great, just what I wanted |
I was implementing a Writable stream and misunderstood `decodeStrings` to mean 'will decode `Buffer`s into `string`s before calling `_write`'. This change adds a little more detail to the description of `decodeStrings` to clarify its effect on a Writable stream & what gets passed to `_write`. Changing the name of the option to `encodeStrings` would make it much easier to understand, but the name was chosen in 2012 and the option used in many projects (22k mentions of 'decodeStringsr in JS projects in GitHub). Deprecating the old name & rolling out a replacement is beyond my capabilities as a first-time contributor. Fixes: nodejs#25464
I was implementing a Writable stream and misunderstood `decodeStrings` to mean 'will decode `Buffer`s into `string`s before calling `_write`'. This change adds a little more detail to the description of `decodeStrings` to clarify its effect on a Writable stream & what gets passed to `_write`. Changing the name of the option to `encodeStrings` would make it much easier to understand, but the name was chosen in 2012 and the option used in many projects (22k mentions of 'decodeStringsr in JS projects in GitHub). Deprecating the old name & rolling out a replacement is beyond my capabilities as a first-time contributor. PR-URL: #25468 Fixes: #25464 Reviewed-By: Anna Henningsen <anna@addaleax.net>
I was implementing a Writable stream and misunderstood `decodeStrings` to mean 'will decode `Buffer`s into `string`s before calling `_write`'. This change adds a little more detail to the description of `decodeStrings` to clarify its effect on a Writable stream & what gets passed to `_write`. Changing the name of the option to `encodeStrings` would make it much easier to understand, but the name was chosen in 2012 and the option used in many projects (22k mentions of 'decodeStringsr in JS projects in GitHub). Deprecating the old name & rolling out a replacement is beyond my capabilities as a first-time contributor. PR-URL: #25468 Fixes: #25464 Reviewed-By: Anna Henningsen <anna@addaleax.net>
I was implementing a Writable stream and misunderstood `decodeStrings` to mean 'will decode `Buffer`s into `string`s before calling `_write`'. This change adds a little more detail to the description of `decodeStrings` to clarify its effect on a Writable stream & what gets passed to `_write`. Changing the name of the option to `encodeStrings` would make it much easier to understand, but the name was chosen in 2012 and the option used in many projects (22k mentions of 'decodeStringsr in JS projects in GitHub). Deprecating the old name & rolling out a replacement is beyond my capabilities as a first-time contributor. PR-URL: #25468 Fixes: #25464 Reviewed-By: Anna Henningsen <anna@addaleax.net>
I was implementing a Writable stream and misunderstood `decodeStrings` to mean 'will decode `Buffer`s into `string`s before calling `_write`'. This change adds a little more detail to the description of `decodeStrings` to clarify its effect on a Writable stream & what gets passed to `_write`. Changing the name of the option to `encodeStrings` would make it much easier to understand, but the name was chosen in 2012 and the option used in many projects (22k mentions of 'decodeStringsr in JS projects in GitHub). Deprecating the old name & rolling out a replacement is beyond my capabilities as a first-time contributor. PR-URL: #25468 Fixes: #25464 Reviewed-By: Anna Henningsen <anna@addaleax.net>
v11.2.0
I am implementing a Writable stream to process output from spawned processes. Since I know that the processes will write utf8-encoded strings, I wanted to implement the stream so the incoming data would arrive as Strings. I was delighted to see
decodeStrings
mentioned underwritable._write
:I didn't quite understand how setting
decodeStrings
to false would result in the stream not getting chunks as Buffers, but I tried it. It didn't work the way I interpreted the docs, so I was quite surprised to see the chunks still arriving as Buffers.After reading the Constructor docs:
and the actual implementation of
decodeChunk
, I realised that the option name didn't match the behavior, and it would be more accurate to call itencodeStrings
(to match the nomenclature used in other languages/libraries when they refer to the act of taking an internal string representation & converting it to a byte sequence using a specified encoding).The Constructor docs confused me, because the option said
decode
and the description saidencode
and I knew they couldn't both be accurate, and so I had to choose between assuming the option name was right (and Strings were decoded from Buffers), or the description was right (and Strings were encoding into Buffers).I'm filing this issue because I'm grumpy about the time it took to understand the behaviour and feel that I would have spent less time to work out my use-case wasn't supported if there was a clearer option name, or docs which made it clear that the option name didn't reflect the behaviour. Something like:
I now know I have to implement something to handle my original problem (decode incoming Buffers into Strings) myself. I'm happy to do that, but if you think the Writable's
decodeStrings
feature could be more configurable, I'd be very happy to use it instead.The text was updated successfully, but these errors were encountered: