-
Notifications
You must be signed in to change notification settings - Fork 30k
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
buffer.write(buffer, 'base64') #11866
Comments
@jorangreef There's always going to be an interim string, since you have to first "decode" ASCII by going from Buffer to string, then decode base64 by going from string to Buffer. Your first snippet is fine, but I'd recommend using the new API: |
@seishun I think he means without creating a V8 String object. It's entirely possible, it's just not something that's currently available AFAIK. |
This is partly available in the |
Because it uses ICU, and base64 isn't a way to encode text as binary data, it's the other way around. IMO supporting it in |
|
@seishun thanks, using the constructor was a typo from habit.
@mscdex yes, that's what I was getting at, avoiding the String allocation. It should be possible, but not provided by the api currently.
@jasnell agreed, hence the suggestion for |
|
to be honest, I'd like to see a revision to What would be more correct would be something like: Buffer.from([...]).encode('base64');
Buffer.from([...]).encode('hex'); Unfortunately |
I agree, it’s been bugging me since I started node that |
I agree it's confusing, but on the other hand, |
@addaleax ... A Buffer creation is equally problematic. |
@jasnell I'd be against adding new APIs unless we are also planning to phase out the old ones, and we know well that it's not as easy as we'd wish. And the existing API isn't exactly bad either. |
Yep, which is why I haven't pursued it. The current API is not painful enough to justify the level of disruption changing it would cause. |
Can this be closed as an answered question? All the ways currently exposed by Node use an temporary string, and that makes sense, because as @seishun explained this question is really asking about base64+ascii “double” encoding. |
Indeed, closing as an answered question. |
In case anyone has an issue with the lack of buffer-to-buffer Base64 encoding/decoding support in Node, I just finished https://github.com/ronomon/base64 as a stop-gap until these and other base64 issues are addressed. The encoder/decoder accepts and returns buffers without allocating any interim V8 Strings. The throughput gain from avoiding unnecessary string allocation is substantial over 4 MB+ buffers. |
What's the fastest way to convert a buffer containing base64-encoded data to a buffer containing binary data?
Something like this?
Is there a way to write the base64 buffer directly into another buffer, without creating any interim strings?
I thought of
binaryBuffer.write(base64Buffer, 'base64')
butwrite()
only accepts strings.The text was updated successfully, but these errors were encountered: