base64 icon indicating copy to clipboard operation
base64 copied to clipboard

Should I use this package, or atob and btoa?

Open macgyver opened this issue 5 years ago • 4 comments

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?

macgyver avatar Dec 10 '18 18:12 macgyver

I had a quick look, and the biggest differences seem to be:

  • atob and btoa 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.

mathiasbynens avatar Dec 11 '18 12:12 mathiasbynens

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.

macgyver avatar Dec 11 '18 15:12 macgyver

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.

macgyver avatar Jun 07 '19 13:06 macgyver

Would rather say, stick to binary if you can, blob, ObjectURLs arraybuffer, TypedArrays (not node:buffer)

base64 is an unnecessary encoding/decoding step

jimmywarting avatar Dec 19 '22 17:12 jimmywarting