base64
base64 copied to clipboard
Should I use this package, or atob and btoa?
A topic for discussion: this repo very closely resembles atob
and btoa
I find myself in a pickle when deciding which library to use - atob
and btoa
seem attractive because of the usage stats, longevity, and update frequency, but this one is written by web hero Mathias Bynens.. would it be possible to describe what (if any) major differences there are between the two options to help us decide?
I had a quick look, and the biggest differences seem to be:
-
atob
andbtoa
do not really attempt to match the HTML spec. - They rely on
Buffer
which is only available in Node.js.
If you're building something that only runs on Node.js, and you're fine with not matching browser implementations exactly, then using atob
/btoa
seems fine.
If you need a zero-dependency pure-JS implementation that matches browsers as closely as possible, then consider using base-64
.
Thanks for the reply! I'm actually not sure why anybody would choose atob
and btoa
over this library, it seems silly to perpetuate the confusing names of the browser functions and not perfectly reproduce their functionality.
Heya, sorry to re-open this conversation but I had another question - I noticed that the popular jsdom
library incorporates a third option: abab
- it has tremendous velocity but I suspect that's primarily because it's a dep of jsdom
... any thoughts on this one? It seems to have basically the same stated purpose as this library, I'm not sure of the details but the only major difference I can detect is that they use the same names as the functions they are designed to emulate.
Would rather say, stick to binary if you can, blob, ObjectURLs arraybuffer, TypedArrays (not node:buffer)
base64 is an unnecessary encoding/decoding step