What the heck is binary?
ASCII
ASCII = American Standard Code for Information Interchange is a character encoding using 7 bits to represent 128 characters. It’s a character encoding that maps text into a number.
Example:
| Char | ASCII |
| A | 65 |
| a | 97 |
| 0 | 48 |
It's how text is stored in memory as bytes.
Base64
Base64 turns binary into an ASCII string.
Base64 encoding schemes are commonly used to encode binary data for storage or transfer over media that can only deal with ASCII text
btoa
https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa
The btoa() method of the Window interface creates a Base64-encoded ASCII string from a binary string
const str = "Hello";
const encoded = btoa(str); // base64 encode
console.log(encoded); // "SGVsbG8="
atob
The atob() method of the Window interface decodes a string of data which has been encoded using Base64 encoding
const decoded = atob(encoded); // decode
console.log(decoded); // "Hello"
Use case
Embed Images in HTML/CSS
Send Binary Data via JSON or GraphQL
Save Binary in local-storage
Transfer Binary via URL
{
"filename": "photo.jpg",
"content": "base64string..."
}
Binary
Binary is a raw data represented in bits (0s and 1s)
Blob
Binary Large Object — a container for binary data. Blob is binary data plus metadata like MIME type.
Readable stream
https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream