From 4aa93197994671082e1ae1b9a6a80047ece9eb33 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Thu, 2 Nov 2023 17:14:16 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=97=A0=E7=94=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/toolFunc.ts | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/src/utils/toolFunc.ts b/src/utils/toolFunc.ts index db173bce..225a0367 100644 --- a/src/utils/toolFunc.ts +++ b/src/utils/toolFunc.ts @@ -1,11 +1,10 @@ /** * @file utils toolFunc.ts * @description 一些工具函数 - * @since Beta v0.3.4 + * @since Beta v0.3.5 */ -import { fs, os, path } from "@tauri-apps/api"; -import type { FileEntry } from "@tauri-apps/api/fs"; +import { os, path } from "@tauri-apps/api"; import { v4 } from "uuid"; /** @@ -68,33 +67,6 @@ export function bytesToSize(bytes: number): string { return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`; } -/** - * @description 获取文件夹大小 - * @since Beta v0.3.4 - * @param {FileEntry[]} cacheInfo - 文件夹信息 - * @param {boolean} isRoot - 是否是根目录 - * @returns {Promise} 文件夹大小 - */ -export async function getDirSize(cacheInfo: FileEntry[], isRoot: false): Promise; -export async function getDirSize(cacheInfo: FileEntry[], isRoot?: true): Promise; -export async function getDirSize( - cacheInfo: FileEntry[], - isRoot?: boolean, -): Promise { - let size = 0; - for (const item of cacheInfo) { - if (item.children) { - const dir = await fs.readDir(item.path); - size += await getDirSize(dir, false); - } else { - const file = await fs.readBinaryFile(item.path); - size += file.byteLength; - } - } - if (isRoot === undefined || isRoot) return bytesToSize(size); - return size; -} - /** * @description 获取缓存目录 * @since Beta v0.3.4