Skip to content

Commit

Permalink
base64辅助类
Browse files Browse the repository at this point in the history
  • Loading branch information
esengine committed Jul 17, 2020
1 parent c96e8b3 commit dccd4e2
Show file tree
Hide file tree
Showing 7 changed files with 390 additions and 2 deletions.
10 changes: 10 additions & 0 deletions demo/libs/framework/framework.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,16 @@ declare class ArrayUtils {
static equals(ary1: number[], ary2: number[]): Boolean;
static insert(ary: any[], index: number, value: any): any;
}
declare class Base64Utils {
private static _keyNum;
private static _keyStr;
private static _keyAll;
static encode: (input: any) => string;
private static _utf8_encode;
static decode(input: any, isNotStr?: boolean): string;
private static _utf8_decode;
private static getConfKey;
}
declare class ContentManager {
protected loadedAssets: Map<string, any>;
loadRes(name: string, local?: boolean): Promise<any>;
Expand Down
122 changes: 122 additions & 0 deletions demo/libs/framework/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -5488,6 +5488,128 @@ var ArrayUtils = (function () {
};
return ArrayUtils;
}());
var Base64Utils = (function () {
function Base64Utils() {
}
Base64Utils._utf8_encode = function (string) {
string = string.replace(/\r\n/g, "\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
}
else if ((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
};
Base64Utils.decode = function (input, isNotStr) {
if (isNotStr === void 0) { isNotStr = true; }
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
input = this.getConfKey(input);
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) {
enc1 = this._keyAll.indexOf(input.charAt(i++));
enc2 = this._keyAll.indexOf(input.charAt(i++));
enc3 = this._keyAll.indexOf(input.charAt(i++));
enc4 = this._keyAll.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
if (chr2 == 0) {
if (isNotStr)
output = output + String.fromCharCode(chr2);
}
else {
output = output + String.fromCharCode(chr2);
}
}
if (enc4 != 64) {
if (chr3 == 0) {
if (isNotStr)
output = output + String.fromCharCode(chr3);
}
else {
output = output + String.fromCharCode(chr3);
}
}
}
output = this._utf8_decode(output);
return output;
};
Base64Utils._utf8_decode = function (utftext) {
var string = "";
var i = 0;
var c = 0;
var c1 = 0;
var c2 = 0;
var c3 = 0;
while (i < utftext.length) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
}
else if ((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i + 1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
}
else {
c2 = utftext.charCodeAt(i + 1);
c3 = utftext.charCodeAt(i + 2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
};
Base64Utils.getConfKey = function (key) {
return key.slice(1, key.length);
};
Base64Utils._keyNum = "0123456789+/";
Base64Utils._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
Base64Utils._keyAll = Base64Utils._keyNum + Base64Utils._keyStr;
Base64Utils.encode = function (input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = this._utf8_encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
}
else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
this._keyAll.charAt(enc1) + this._keyAll.charAt(enc2) +
this._keyAll.charAt(enc3) + this._keyAll.charAt(enc4);
}
return this._keyStr.charAt(Math.floor((Math.random() * this._keyStr.length))) + output;
};
return Base64Utils;
}());
var ContentManager = (function () {
function ContentManager() {
this.loadedAssets = new Map();
Expand Down
2 changes: 1 addition & 1 deletion demo/libs/framework/framework.min.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions source/bin/framework.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,16 @@ declare class ArrayUtils {
static equals(ary1: number[], ary2: number[]): Boolean;
static insert(ary: any[], index: number, value: any): any;
}
declare class Base64Utils {
private static _keyNum;
private static _keyStr;
private static _keyAll;
static encode: (input: any) => string;
private static _utf8_encode;
static decode(input: any, isNotStr?: boolean): string;
private static _utf8_decode;
private static getConfKey;
}
declare class ContentManager {
protected loadedAssets: Map<string, any>;
loadRes(name: string, local?: boolean): Promise<any>;
Expand Down
122 changes: 122 additions & 0 deletions source/bin/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -5488,6 +5488,128 @@ var ArrayUtils = (function () {
};
return ArrayUtils;
}());
var Base64Utils = (function () {
function Base64Utils() {
}
Base64Utils._utf8_encode = function (string) {
string = string.replace(/\r\n/g, "\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
}
else if ((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
};
Base64Utils.decode = function (input, isNotStr) {
if (isNotStr === void 0) { isNotStr = true; }
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
input = this.getConfKey(input);
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) {
enc1 = this._keyAll.indexOf(input.charAt(i++));
enc2 = this._keyAll.indexOf(input.charAt(i++));
enc3 = this._keyAll.indexOf(input.charAt(i++));
enc4 = this._keyAll.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
if (chr2 == 0) {
if (isNotStr)
output = output + String.fromCharCode(chr2);
}
else {
output = output + String.fromCharCode(chr2);
}
}
if (enc4 != 64) {
if (chr3 == 0) {
if (isNotStr)
output = output + String.fromCharCode(chr3);
}
else {
output = output + String.fromCharCode(chr3);
}
}
}
output = this._utf8_decode(output);
return output;
};
Base64Utils._utf8_decode = function (utftext) {
var string = "";
var i = 0;
var c = 0;
var c1 = 0;
var c2 = 0;
var c3 = 0;
while (i < utftext.length) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
}
else if ((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i + 1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
}
else {
c2 = utftext.charCodeAt(i + 1);
c3 = utftext.charCodeAt(i + 2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
};
Base64Utils.getConfKey = function (key) {
return key.slice(1, key.length);
};
Base64Utils._keyNum = "0123456789+/";
Base64Utils._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
Base64Utils._keyAll = Base64Utils._keyNum + Base64Utils._keyStr;
Base64Utils.encode = function (input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = this._utf8_encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
}
else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
this._keyAll.charAt(enc1) + this._keyAll.charAt(enc2) +
this._keyAll.charAt(enc3) + this._keyAll.charAt(enc4);
}
return this._keyStr.charAt(Math.floor((Math.random() * this._keyStr.length))) + output;
};
return Base64Utils;
}());
var ContentManager = (function () {
function ContentManager() {
this.loadedAssets = new Map();
Expand Down
2 changes: 1 addition & 1 deletion source/bin/framework.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit dccd4e2

Please sign in to comment.