Base64 encoding allows us to transform binary data into text data. The reasons for this are rooted in the history of network protocols, but it is still a widely used form of encoding when shipping binary data.
For example, binary e-mail attachments are first converted to base64 before being sent. It happens to be a handy way to include images within the context of an e-mail body.
In these recipes, we will see how to encode and decode binary and base64-encoded files.
Node provides a string Buffer
class that can represent text data in a variety of encodings, including ASCII
, UTF-8
, and Base-64
. This Buffer
class will be the core of our conversion operations.
Node supports base64 encoding without the need of an external module. We will be using Node's built-in capabilities.