You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
866 B
44 lines
866 B
|
7 months ago
|
/*
|
||
|
|
* base64.js: An extremely simple implementation of base64 encoding / decoding using node.js Buffers
|
||
|
|
*
|
||
|
|
* (C) 2010, Nodejitsu Inc.
|
||
|
|
*
|
||
|
|
*/
|
||
|
|
|
||
|
|
var base64 = exports;
|
||
|
|
|
||
|
|
//
|
||
|
|
// ### function encode (unencoded)
|
||
|
|
// #### @unencoded {string} The string to base64 encode
|
||
|
|
// Encodes the specified string to base64 using node.js Buffers.
|
||
|
|
//
|
||
|
|
base64.encode = function (unencoded) {
|
||
|
|
var encoded;
|
||
|
|
|
||
|
|
try {
|
||
|
|
encoded = new Buffer(unencoded || '').toString('base64');
|
||
|
|
}
|
||
|
|
catch (ex) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
return encoded;
|
||
|
|
};
|
||
|
|
|
||
|
|
//
|
||
|
|
// ### function decode (encoded)
|
||
|
|
// #### @encoded {string} The string to base64 decode
|
||
|
|
// Decodes the specified string from base64 using node.js Buffers.
|
||
|
|
//
|
||
|
|
base64.decode = function (encoded) {
|
||
|
|
var decoded;
|
||
|
|
|
||
|
|
try {
|
||
|
|
decoded = new Buffer(encoded || '', 'base64').toString('utf8');
|
||
|
|
}
|
||
|
|
catch (ex) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
return decoded;
|
||
|
|
};
|