-
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
Writable
doesn't correctly count size of strings
#52818
Comments
@nodejs/streams @mcollina |
I think we should fix it. Is this a recent regression? |
So the fix would be to call |
|
@benjamingr it seems to be correctly calculated in v10 and v0.10. See https://github.com/nodejs/node/blob/v10.x/lib/_stream_writable.js#L374 and https://github.com/nodejs/node/blob/v0.10/lib/_stream_writable.js#L204 (note |
It actually seems to be correctly calculated also on main. See node/lib/internal/streams/writable.js Line 465 in 2c55652
|
Confirmed. const { Writable } = require('stream');
const w = new Writable({
write() {}
});
w.write('€');
w.write('€');
console.log(w.writableLength); // 6 I think we can close this. |
@lpinca that's just one case though? |
To be clear:
This is across streams in several places - the fact writable works with decodeStrings set to true doesn't mean it's not a bug elsewhere? |
The issue description did not mention the |
I think using |
I think whenever we have a stream of strings and not buffers we should use byteLength (or just use Buffer.byteLength for everything) and if there is no performance impact land it. (though byteLength would use its length as utf-8 and not utf-16 "as if it was a buffer encoded as utf-8" which may be desired?) |
Use the UTF-8 byte length of the string when the `decodeStrings` option is set to `false`. Fixes: nodejs#52818
Use the UTF-8 byte length of the string when the `decodeStrings` option is set to `false`. Fixes: nodejs#52818
Use the byte length of the string when the `decodeStrings` option is set to `false`. Fixes: nodejs#52818
Documents that we calculate the highWaterMark value of streams operating on strings using the number of UTF-16 code units. Fixes: #52818
Documents that we calculate the highWaterMark value of streams operating on strings using the number of UTF-16 code units. Fixes: #52818
Documents that we calculate the highWaterMark value of streams operating on strings using the number of UTF-16 code units. Fixes: nodejs#52818 PR-URL: nodejs#52842 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Documents that we calculate the highWaterMark value of streams operating on strings using the number of UTF-16 code units. Fixes: nodejs#52818 PR-URL: nodejs#52842 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Minor bug. Not sure if it's worth the performance impact of fixing.
When calculating the currently buffered length we are not correctly calculating the byte length of strings, we just use the string length.
The text was updated successfully, but these errors were encountered: