/*-- Copyright 2009-2010 by Stefan Rusterholz. All rights reserved. You can choose between MIT and BSD-3-Clause license. License file will be added later. --*/ /** * mixin cc.Codec.Base64 */ cc.Codec.Base64 = {name:'Jacob__Codec__Base64'}; cc.Codec.Base64._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; /** *
* cc.Codec.Base64.decode(input[, unicode=false]) -> String (http://en.wikipedia.org/wiki/Base64). *
* @function * @param {String} input The base64 encoded string to decode * @return {String} Decodes a base64 encoded String * @example * //decode string * cc.Codec.Base64.decode("U29tZSBTdHJpbmc="); // => "Some String" */ cc.Codec.Base64.decode = function Jacob__Codec__Base64__decode(input) { var output = [], chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++)); enc4 = this._keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output.push(String.fromCharCode(chr1)); if (enc3 != 64) { output.push(String.fromCharCode(chr2)); } if (enc4 != 64) { output.push(String.fromCharCode(chr3)); } } output = output.join(''); return output; }; /** *
* Converts an input string encoded in base64 to an array of integers whose
* values represent the decoded string's characters' bytes.
*