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

Asked

Viewed 594 times

3

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

The question is, where do these names come from?

  • 3

    Probably inspired by atoi (ASCII to integer) of C, atob should mean ASCII to Base64, although today this function converts UTF-8 to Base64, not ASCII.

  • 4

    I don’t know, I just know they’re bad names. atob gives me the impression that it is "ASCII to Base64", but in fact it is the opposite...

  • 1

    Yeah, I also did some research and found this. But it’s really the other way around... :v

1 answer

4


Researching I found this question from Soen. The text below is an adaptation of several answers that have there (and some more addenda my).


One of the answers mentions a tweet brendan Eich (considered the javascript creator), that said these names come from old Unix systems. Including, the tweet of it mentions the handbook of btoa, in which we have the following:

NAME

       btoa - binary to ascii conversion

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

To specification of WHATWG supports 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 are 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, the 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 with Base64:

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

What happens is that - at least in my case - I usually use Base64 with text, and I 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 the b means "base 64," and I have to remember that it’s actually the opposite of what I’m thinking. But now that I find out it means "Inary," it makes more sense...

Still, I still think they’re terrible names. Maybe if they were base64Encode and base64Decode, it would be clearer what they do.

  • 1

    Thank you for another of your excellent answers!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.