Book Image

CoffeeScript Application Development Cookbook

By : Mike Hatfield
Book Image

CoffeeScript Application Development Cookbook

By: Mike Hatfield

Overview of this book

Table of Contents (18 chapters)
CoffeeScript Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Working with base64 encoding


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.

Encoding a string as base64

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.

Getting ready

Node supports base64 encoding without the need of an external module. We will be using Node's built-in capabilities.

How to do it...

We will create a Node module that exposes a method to convert ASCII toBase64() and another Node to convert to ASCII fromBase64():

  1. Create a function...