bun icon indicating copy to clipboard operation
bun copied to clipboard

Buffer.from needs to read `data:` attribute for base64 strings

Open Jarred-Sumner opened this issue 2 years ago • 1 comments

That's the cause of https://github.com/oven-sh/bun/issues/1729

Jarred-Sumner avatar Jan 07 '23 01:01 Jarred-Sumner

Are we talking about Node.js Buffer class here? :thinking:

$ cat test.js
const base64 = btoa("PASS");

console.log("PASS -->", base64);
console.log(Buffer.from(base64, "base64").toString());
console.log(Buffer.from("data:text/plain;base64," + base64, "base64").toString());
$ node -v
v18.12.1
$ node test.js
PASS --> UEFTUw==
PASS
u�Z��m��Z�vڱ�PASS

alexlamsl avatar Jan 07 '23 10:01 alexlamsl

Non-issue, both Bun and Node.js do the same thing:

❯ bun base64.js
PASS --> UEFTUw==
PASS
u�Z��m��Z�vڱ�PASS
❯ node base64.js 
PASS --> UEFTUw==
PASS
u�Z��m��Z�vڱ�PASS

Electroid avatar Oct 25 '23 21:10 Electroid