Problem with parsing `base64url` from a `Buffer (node)`
help , it works in bun but not in Deno, I don't know if is a bug from them or it's not implemented here,it also works in node:
8 Replies
Based on the documentation, Deno does not have built-in support for the
base64url
encoding in the Buffer.from()
method. The Buffer.from()
method in Node.js does not support base64url
encoding either. The discrepancy you're seeing might be due to differences in how the Buffer.from()
method is implemented in bun, Node.js, and Deno.
In Deno, you can use the built-in TextDecoder
and atob
functions to decode base64 strings. However, these functions do not support base64url
directly. You would need to convert the base64url
string to a regular base64 string first. Here's how you can do it:
Please note that this information is not explicitly stated in the documentation, but it's a common way to handle base64url
in JavaScript.That's actually incorrect, the official types includes 'base64url'
I apologize for the confusion. The official Node.js documentation does not list 'base64url' as a valid encoding for the Buffer.from() method. However, if 'base64url' is working in your Node.js environment, it might be due to a third-party library or a custom implementation that extends the native Buffer functionality.
In Deno, you might need to manually convert the 'base64url' string to a regular base64 string before decoding it. Here's how you can do it:
This code replaces '-' with '+' and '_' with '/' in the 'base64url' string, converting it to a regular base64 string. Then it uses the atob() function to decode the base64 string.
Well, I will need to make a deno's only implementation that will be slower than bun's
I'm seeing the same bug with Buffer.from and base64url. Its returning a buffer that is mostly zeros.
The AI doesn't know that Deno has a module for Base64URL.
That would do, I hope is fast because the other implementation works but it's super slow
Hey folks, do you mind opening a bug about this? We'll fix it!
I will indeed!
done!