Skip to content

Instantly share code, notes, and snippets.

@Marak
Created February 8, 2011 00:41
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save Marak/815609 to your computer and use it in GitHub Desktop.
Save Marak/815609 to your computer and use it in GitHub Desktop.
An extremely simple implementation of base64 encoding / decoding using node.js Buffers
/*
* base64.js: An extremely simple implementation of base64 encoding / decoding using node.js Buffers
*
* (C) 2010, Nodejitsu Inc.
*
*/
var base64 = exports;
base64.encode = function (unencoded) {
return new Buffer(unencoded || '').toString('base64');
};
base64.decode = function (encoded) {
return new Buffer(encoded || '', 'base64').toString('utf8');
};
@atmos
Copy link

atmos commented Feb 8, 2011

Jesus, I just did this in a way more painful way today. Thanks!

@Marak
Copy link
Author

Marak commented Feb 8, 2011

THATS COPYRIGHT NODEJITSU IF YOU STEAL OUR CODE IM TOTALLY GONNA SUE YOU

Kidding :-p

I'm trying to think if there is a good way to include the other encoding in this sugar syntax api, maybe try to get this in core. Do you have any suggestions?

@atmos
Copy link

atmos commented Feb 8, 2011

Nah I think it's trivial enough that it should just be documented somewhere perhaps. A lot of older node libs have vendored an even older base64.js file and it'd be nice if people didn't have to do that.

@Marak
Copy link
Author

Marak commented Feb 8, 2011

Word, I know I have base64.js files kicking around from before the Buffer object could this do. Maybe we'll do a quick blog post.

@indexzero
Copy link

Haha, nice fork of my gist :0D
https://gist.github.com/718390

@Marak
Copy link
Author

Marak commented Feb 8, 2011

I'm pretty sure you wrote this one too? I just copy pasted from broodmother.

@RikyTres
Copy link

What's "exports" at line 8?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment