Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An extremely simple implementation of base64 encoding / decoding using node.js Buffers
//
// Super simple base64 encoding / decoding with node.js
//
var base64 = exports = {
encode: function (unencoded) {
return new Buffer(unencoded).toString('base64');
},
decode: function (encoded) {
return new Buffer(encoded, 'base64').toString('utf8');
}
};
@ryanmcgrath

This comment has been minimized.

Copy link

ryanmcgrath commented Nov 28, 2010

This is very, very handy. Thank you.

@budiony

This comment has been minimized.

Copy link

budiony commented Dec 7, 2016

The Buffer constructor is deprecated according to the documentation.
It can lead to vulnerability that can result from using it in the ws library.
Instead, use something like this:

return Buffer.from("Hello World").toString('base64');
and
return Buffer.from("SGVsbG8gV29ybGQ=", 'base64').toString('utf8');

@rostag

This comment has been minimized.

Copy link

rostag commented Jan 30, 2017

@budiony — thanks, saved me a lot of nerves =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.