修复fw中没有atob和btoa函数的问题

This commit is contained in:
huangxd- committed 2026-02-27 23:41:16 +08:00
1 parent afcf4b872e
commit e22f81b5f3
2 files changed
+3 -20

No files matched your search

+2 -2
View File
@@ -437,7 +437,7 @@ function pkcs7Unpad(data){
}
// ====================== Base64 解码 ======================
function base64ToBytes(b64) {
export function base64ToBytes(b64) {
// 先把 Base64 字符串转换成普通字符
const binaryString = (typeof atob === 'function')
? atob(b64) // 浏览器环境
@@ -581,7 +581,7 @@ function str2bytes(str) {
}
// ===================== Base64 编码 =====================
function bytesToBase64(bytes) {
export function bytesToBase64(bytes) {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
let result = '';
let i;
+1 -18
View File
@@ -1,4 +1,4 @@
import { md5, stringToUtf8Bytes, utf8BytesToString } from "./codec-util.js";
import { md5, stringToUtf8Bytes, utf8BytesToString, bytesToBase64, base64ToBytes } from "./codec-util.js";
const HANJUTV_VERSION = "6.5.3";
const HANJUTV_VC = "a_7980";
@@ -45,23 +45,6 @@ function utf8Decode(bytes) {
return utf8BytesToString(bytes);
}
function bytesToBase64(bytes) {
if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
let binary = "";
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
return btoa(binary);
}
function base64ToBytes(base64) {
if (typeof Buffer !== "undefined") return new Uint8Array(Buffer.from(base64, "base64"));
const binary = atob(base64);
const bytes = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
return bytes;
}
function xorBytes(a, b) {
const out = new Uint8Array(a.length);
for (let i = 0; i < a.length; i++) out[i] = a[i] ^ b[i];