-
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
Feature proposal: buffer.convert(value[, fromEnc], toEnc) #9797
Comments
Or perhaps |
I’d be okay with it, although I would probably prefer it as And you should probably specify both encodings explicitly. For this conversion to make sense, one of these has to be a binary-to-text encoding like /cc @nodejs/buffer |
@ChALkeR I am not sure you can compare the situation wrt default encodings here. For If you prefer it another way, I guess that’s fine, but I really think explicit encodings would be better here. |
Not sure this is a good idea.
|
@seishun Thanks.
|
I didn't say that the order is better one or the other way. My concern is that people will likely get confused either way.
But they still both live in the |
@ChALkeR Leave this open? (I imagine so, but it's been inactive for long enough that I figure it's worth checking.) |
This is essentially |
Not quite. Buffer.transcode converts a buffer to a buffer. This converts a string to a string. |
so the proposal itself has a prototype code, not sure why it got stalled for 18 months. Calling for contributors! |
I thought @seishun brought up some valid concerns. Also |
@apapirovski - fair point, while I also don't have strong opinion either way (not much demanded from users vs a convenient API abstraction) my motivation was to see how this can be moved towards a conclusion. If we have consensus on no action at this point, we can close this out. |
I personally think The only compelling reason I can see is that it might be possible to improve the performance of that operation. But that would be a much more complicated implementation than suggested and it is not clear how significant the difference would actually be. |
@BridgeAR I disagree — people do that a lot, and some still use |
@seishun I am also not sure if this should be on the |
@ChALkeR if they did not move away from |
There's been no activity on this in over 2 years and it can be accomplished using existing API. Closing. |
I think that Node has no way to convert buffer encodings from one buffer to another without creating an intermediary string and doing associated GC? |
@jorangreef This issue here seems to be about a |
Thanks @addaleax |
While investigating the
Buffer
usage, I noticed one thing — in many (really, many) cases,Buffer
s are constructed just for the sake of base64-encoding a string.base64-encodinng is used in many places, like auth headers, data uris, messages, etc.
With the new API, that would look like
Buffer.from(from).toString(encoding)
.With the old API, that would look like
new Buffer(from).toString(encoding)
(note that this lacks checks).So I propose to add a small utility function, e.g.
Note that the impl does not default to
utf-8
and forces an encoding to be specified, this way it would be more clear what the userspace code does.Sure, that could be done on userside, but this doesn't deserve a separate package, and re-implementing that in all the packages that do conversion also doesn't look very good to me.
Note that if we have had such method earlier, the usage of
Buffer
withoutnew
(and otherBuffer
-related issues) would have been measurably lower.If everyone thinks that this is a good idea, I am willing to file a PR for it (impl/docs/tests).
The text was updated successfully, but these errors were encountered: