From 6b1714f4edea6d3bf817d57011aa2e9754932445 Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Tue, 6 May 2025 23:23:15 +0800 Subject: [PATCH] perf: remove base64Conver --- apps/web-antd/src/utils/base64Conver.ts | 48 ------------------------- 1 file changed, 48 deletions(-) delete mode 100644 apps/web-antd/src/utils/base64Conver.ts diff --git a/apps/web-antd/src/utils/base64Conver.ts b/apps/web-antd/src/utils/base64Conver.ts deleted file mode 100644 index 7cd4e298..00000000 --- a/apps/web-antd/src/utils/base64Conver.ts +++ /dev/null @@ -1,48 +0,0 @@ -// TODO @芋艿:需要优化下 -// TODO @芋艿:是不是可以共用么? -/** - * @description: base64 to blob - */ -export function dataURLtoBlob(base64Buf: string): Blob { - const arr = base64Buf.split(','); - const typeItem = arr[0]; - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const mime = typeItem!.match(/:(.*?);/)![1]; - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const bstr = window.atob(arr[1]!); - let n = bstr.length; - const u8arr = new Uint8Array(n); - while (n--) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - u8arr[n] = bstr.codePointAt(n)!; - } - return new Blob([u8arr], { type: mime }); -} - -/** - * img url to base64 - * @param url - */ -export function urlToBase64(url: string, mineType?: string): Promise { - return new Promise((resolve, reject) => { - let canvas = document.createElement('CANVAS') as HTMLCanvasElement | null; - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const ctx = canvas!.getContext('2d'); - - const img = new Image(); - img.crossOrigin = ''; - img.addEventListener('load', () => { - if (!canvas || !ctx) { - // eslint-disable-next-line prefer-promise-reject-errors - return reject(); - } - canvas.height = img.height; - canvas.width = img.width; - ctx.drawImage(img, 0, 0); - const dataURL = canvas.toDataURL(mineType || 'image/png'); - canvas = null; - resolve(dataURL); - }); - img.src = url; - }); -}