Decoding base64 encoded binary data
Until very recently, JavaScript didn't have any native support for storing binary data types. Most binary data was handled as strings. Binary data that could not be handled using strings (for example, images) was handled as base64 encoded strings.
Note
Base64 is a method to encode binary data by converting groups of bytes into groups of base64 numbers. The goal is to avoid data loss by safely representing binary data using only printable characters which will not be interpreted in a special way.
HTML5 has much better support for binary data, it can be stored and manipulated using the ArrayBuffer
class and the typed array classes. However, legacy libraries and API may still use base64 data. In order to do more efficient binary processing in modern browsers, we might want to convert this data into array buffers.
In this recipe, we're going to write a conversion function that converts base64 encoded strings to array buffers.
Getting ready
To write this function...