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.


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 ...

Get HTML5 Data and Services Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.