将Base64对项内的转换代码替换为Uint8Array原生方法(但是太新了,用的应该是core-js内的polyfill)
This commit is contained in:
parent
c87cd6fb0b
commit
f996de11a0
File diff suppressed because one or more lines are too long
|
@ -1,11 +1,11 @@
|
||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@html2canvas/html2canvas": "^1.6.3",
|
"@html2canvas/html2canvas": "^1.6.3",
|
||||||
"@xmldom/xmldom": "^0.9.6",
|
"@xmldom/xmldom": "^0.9.8",
|
||||||
"@zxing/library": "^0.21.3",
|
"@zxing/library": "^0.21.3",
|
||||||
"core-js-bundle": "^3.39.0",
|
"core-js-bundle": "^3.41.0",
|
||||||
"mime": "^4.0.6",
|
"mime": "^4.0.6",
|
||||||
"opencc-js": "^1.0.5",
|
"opencc-js": "^1.0.5",
|
||||||
"xml-formatter": "^3.6.3"
|
"xml-formatter": "^3.6.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,6 @@ Blob.prototype.toBase64 = function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @readonly
|
* @readonly
|
||||||
* @enum {boolean}
|
* @enum {boolean}
|
||||||
|
@ -130,7 +129,21 @@ const Base64 = {
|
||||||
const str = decoder.decode(view);
|
const str = decoder.decode(view);
|
||||||
return str;
|
return str;
|
||||||
},
|
},
|
||||||
//Base64还原成Uint8Array
|
bytesToBase64DataUrl: async function(bytes, type = "application/octet-stream") {
|
||||||
|
return await new Promise((resolve, reject) => {
|
||||||
|
const reader = Object.assign(new FileReader(), {
|
||||||
|
onload: () => resolve(reader.result),
|
||||||
|
onerror: () => reject(reader.error),
|
||||||
|
});
|
||||||
|
reader.readAsDataURL(new File([bytes], "", { type }));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
dataUrlToBytes: async function(dataUrl) {
|
||||||
|
const res = await fetch(dataUrl);
|
||||||
|
return new Uint8Array(await res.arrayBuffer());
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
//Base64还原成Uint8Array,已经被原生的 Uint8Array.fromBase64() 替代。
|
||||||
decodeToUint8Array: function base64DecToArr(sBase64, nBlocksSize) {
|
decodeToUint8Array: function base64DecToArr(sBase64, nBlocksSize) {
|
||||||
function b64ToUint6(nChr) {
|
function b64ToUint6(nChr) {
|
||||||
return nChr > 64 && nChr < 91
|
return nChr > 64 && nChr < 91
|
||||||
|
@ -172,7 +185,7 @@ const Base64 = {
|
||||||
|
|
||||||
return taBytes;
|
return taBytes;
|
||||||
},
|
},
|
||||||
//Uint8Array编码成Base64
|
//Uint8Array编码成Base64,已经被原生的 Uint8Array.prototype.toBase64() 替代。
|
||||||
encodeFromUint8Array: function base64EncArr(aBytes) {
|
encodeFromUint8Array: function base64EncArr(aBytes) {
|
||||||
function uint6ToB64(nUint6) {
|
function uint6ToB64(nUint6) {
|
||||||
return nUint6 < 26
|
return nUint6 < 26
|
||||||
|
@ -215,24 +228,7 @@ const Base64 = {
|
||||||
(nMod3 === 2 ? "" : nMod3 === 1 ? "=" : "==")
|
(nMod3 === 2 ? "" : nMod3 === 1 ? "=" : "==")
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
bytesToBase64DataUrl: async function(bytes, type = "application/octet-stream") {
|
*/
|
||||||
return await new Promise((resolve, reject) => {
|
|
||||||
const reader = Object.assign(new FileReader(), {
|
|
||||||
onload: () => resolve(reader.result),
|
|
||||||
onerror: () => reject(reader.error),
|
|
||||||
});
|
|
||||||
reader.readAsDataURL(new File([bytes], "", { type }));
|
|
||||||
});
|
|
||||||
},
|
|
||||||
dataUrlToBytes: async function(dataUrl) {
|
|
||||||
const res = await fetch(dataUrl);
|
|
||||||
return new Uint8Array(await res.arrayBuffer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Buffer转16进制字符串
|
|
||||||
Uint8Array.prototype.toHex1 = function() {
|
|
||||||
return [...this].map(n=>n.toString(16).padStart(2,'0')).join('');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2195,7 +2195,7 @@ function reloadFormationData(event) {
|
||||||
}
|
}
|
||||||
//2025年3月27日之后的 Uint16 数组转 Base64
|
//2025年3月27日之后的 Uint16 数组转 Base64
|
||||||
else if (obj.ui16) {
|
else if (obj.ui16) {
|
||||||
const ui8arr = Base64.decodeToUint8Array(obj.ui16);
|
const ui8arr = Uint8Array.fromBase64(obj.ui16);
|
||||||
const idArr = ArrayConvert.BufferToNumberArray(ui8arr, Uint16Array, Endian.little);
|
const idArr = ArrayConvert.BufferToNumberArray(ui8arr, Uint16Array, Endian.little);
|
||||||
return idArr;
|
return idArr;
|
||||||
}
|
}
|
||||||
|
@ -4990,7 +4990,9 @@ function initialize() {
|
||||||
const idArr = searchMonList.originalHeads?.map(head=>head.card.id) ?? [];
|
const idArr = searchMonList.originalHeads?.map(head=>head.card.id) ?? [];
|
||||||
if (idArr.length > 0) {
|
if (idArr.length > 0) {
|
||||||
const ui16Arr = ArrayConvert.NumberArrayToBuffer(idArr, Uint16Array, Endian.little);
|
const ui16Arr = ArrayConvert.NumberArrayToBuffer(idArr, Uint16Array, Endian.little);
|
||||||
const b64 = Base64.encodeFromUint8Array(new Uint8Array(ui16Arr.buffer));
|
|
||||||
|
console.log(ui16Arr, new Uint8Array(ui16Arr.buffer));
|
||||||
|
const b64 = (new Uint8Array(ui16Arr.buffer)).toBase64();
|
||||||
const outObj = {
|
const outObj = {
|
||||||
"ui16": b64
|
"ui16": b64
|
||||||
};
|
};
|
||||||
|
|
|
@ -44231,11 +44231,11 @@ const cachesMap = new Map([
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"script-universal_function.js",
|
"script-universal_function.js",
|
||||||
"312ac475579456dbff44887ccaceb658"
|
"74aa71916cf95d943fab1ce6476ddabb"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"script.js",
|
"script.js",
|
||||||
"c6c3de98108ff05bcd1099a8f39907e8"
|
"651dc95a440c6432688728ba4f0aec32"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"solo.html",
|
"solo.html",
|
||||||
|
|
Loading…
Reference in New Issue