Re:Goodbye, Node.js Buffer
by kev946 on Tuesday October 24, 2023 @10:14AM
(#37999429)
I find buffer useful for its conversion functions to/from different encodings, e.g., `Buffer.from(data, 'hex')` or `Buffer.toString('base64')`. Is there a good way to do this with `Uint8Array`?
[ Parent
| on HN ]
You can use ‘atob’ and ‘btoa’ functions for some of that.
Although those functions operate on "binary strings", not Uint8Arrays, and there is no especially clean way that vanilla JS exposes to convert between the two that I am aware of.
Those functions are fundamentally broken:
https://developer.mozilla.org/en-US/docs/Glossary/Base64#jav...
See the whole section on converting arbitrary binary data and the complex ways to do it.
Re:Goodbye, Node.js Buffer
by davidmurdoch on Tuesday October 24, 2023 @10:17AM
(#37999478)
Polyfill Buffer.
I would prefer not install any dependency if possible, I don't see a necessity of installing a polyfill just to not use the built in one because it's node specific.
People are working on bringing Base64/Hex conversion to JavaScript: https://github.com/tc39/proposal-arraybuffer-base64
I also provide a package to make the transition easier: https://github.com/sindresorhus/uint8array-extras (Feel free to copy-paste the code if you don't want another dependency)
Thanks for all the utility belts you've provided to the ecosystem.
It's insane to me that something as simple as concatenating an array needs a library, but as I've shown upthread, Uint8Arrays are way too complicated to work with.