-
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
Document how to use StringDecoder in combination with stream.Transform #15369
Comments
I would like to work on this one. |
is this issue still open? I would like to tackle it , but I see @chungngoops, you might me already working on it? |
@dantesolis just go ahead, I'm working on it but it's ok. |
@mcollina I am digging into this issue and I would love to know if some of my conclusions are right before proposing a PR.
@chungngoops @dantesolis are you actively working on it? |
|
AFAIK this is due to the increasing number of checks that should be done in
Something like this? class StringWritable extends Writable {
constructor (options) {
super(options)
const state = this._writableState
this._decoder = new StringDecoder(state.defaultEncoding)
this._data = ''
}
_write (chunk, encoding, callback) {
if (encoding === 'buffer') {
chunk = this._decoder.write(chunk)
}
this._data += chunk
callback()
}
} |
You are missing some data that might be left within the stringdecoder. Call |
I'd be curious to see the performance comparison when using |
@jasnell |
@addaleax ... sure it is :-) const { TextDecoder } = require('util');
class StringWritable extends Writable {
constructor (options) {
super(options)
const state = this._writableState
this._decoder = new TextDecoder()
this._data = ''
}
_write (chunk, encoding, callback) {
if (encoding === 'buffer') {
chunk = this._decoder.decode(chunk, { stream: true })
}
this._data += chunk
callback()
}
} See the |
@jasnell Oh, nice. In that case we might actually want to do away with |
@addaleax FYI currently StringDecoder is actually used as a fallback for TextDecoder when ICU is disabled: Lines 431 to 508 in f8063d5
|
Can't do that entirely yet because TextDecoder does not support hex or base64 |
Improved stream documentation with an example of how to decode buffers to strings within a custom Writable. Fixes: nodejs/node#15369 PR-URL: nodejs/node#16403 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Improved stream documentation with an example of how to decode buffers to strings within a custom Writable. Fixes: nodejs/node#15369 PR-URL: nodejs/node#16403 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Improved stream documentation with an example of how to decode buffers to strings within a custom Writable. Fixes: nodejs#15369 PR-URL: nodejs#16403 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Improved stream documentation with an example of how to decode buffers to strings within a custom Writable. Fixes: nodejs/node#15369 PR-URL: nodejs/node#16403 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
In #7315 and #7425, it was discussed how to add string decoding capabilities to
Writable
. However, that is very tricky to implement without a performance regression. At the bare minimum, we should document this inside the streams API docs.See https://github.com/mcollina/split2/blob/master/index.js as an example.
The text was updated successfully, but these errors were encountered: