Files
NapCatQQ/.pnpm-store/v3/files/2f/b311d1307a6bb2f628c6a68ffce1d2ce6be9ea6db018b7ea507ed6a82170c1887655a358560c34206aca277477cfb640ae6d18428cbff74d7652756f454a64
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

39 lines
927 B
Plaintext

/**
* @file 二进制byte流转base64编码
* @author mengke01(kekee000@gmail.com)
*/
/**
* 二进制byte流转base64编码
*
* @param {ArrayBuffer|Array} buffer ArrayBuffer对象
* @return {string} base64编码
*/
export default function bytes2base64(buffer) {
let str = '';
let length;
let i;
// ArrayBuffer
if (buffer instanceof ArrayBuffer) {
length = buffer.byteLength;
const view = new DataView(buffer, 0, length);
for (i = 0; i < length; i++) {
str += String.fromCharCode(view.getUint8(i, false));
}
}
// Array
else if (buffer.length) {
length = buffer.length;
for (i = 0; i < length; i++) {
str += String.fromCharCode(buffer[i]);
}
}
if (!str) {
return '';
}
return typeof btoa !== 'undefined'
? btoa(str)
: Buffer.from(str, 'binary').toString('base64');
}