Where do the names "atob" and "btoa"come from?

In JavaScript, for example, we use the functions atob e btoa to manage codes in base64, decoding and encoding, respectively.

The question is, where do these names come from?

Author: hkotsubo, 2019-09-26

1 answers

Searching I found this question from Soen . The text below is an adaptation of several answers you have there (and a few more addenda of mine).


One of the answers mentions a tweet by Brendan Eich (considered the creator of JavaScript), who said that these names come from old Unix systems. Including, his tweet mentions the btoa, in which we have the following:

NAME

       btoa - binary to ascii conversion

Or that is, b means " binary "and a means"ascii". So the idea of btoa ("binary to ascii") is to convert from binary to ASCII, and atob ("ascii to binary") does the reverse.

The WHATWG specification corroborates with this definition:

In these APIs, for mnemonic purposes, the "b" can be considered to stand for "binary", and the "A" for "ASCII". In practice, though, for primarily historical reasons, both the input and output of these functions has Unicode strings.

Note that although conversions are between "binary" and "ascii", the specification mentions that in practice JavaScript functions receive and return strings (in other languages, such as Java, conversion functions return arrays of bytes, although there may be others that return strings).


Another answer explains the reasoning behind these names, and their relationship to Base64:

Since the Base64 encoding results in a string in which all characters belong to a subset of ASCII, then the a ("ascii") represents the Base64 encoded text. The b ("binary") indicates that what will be converted to Base 64 can be anything. And it's true: basically, the base 64 algorithm serves to encode any string of bytes (not just text, but any other arbitrary string of bytes, no matter what they represent).

What happens is that - at least in my case-I usually use Base64 with text, and often forget that it also works with any bytes. In the specific case of atob and btoa, these names have always led me to think that b means "base 64", and I have to remember that it is actually the opposite of what I am thinking. But now that I've figured out what "binary" means, it makes more sense...

Even so, I continue thinking they're bad names. Maybe if they were base64Encode and base64Decode, it would be clearer what they do.

 4
Author: hkotsubo, 2019-09-26 13:52:12