feat: cycleTransferStats

This commit is contained in:
hamster1963
2024-11-29 10:00:48 +08:00
parent 2462dfc21b
commit 6e676022e9
6 changed files with 198 additions and 16 deletions

11
src/lib/format.ts Normal file
View File

@@ -0,0 +1,11 @@
export function formatBytes(bytes: number, decimals = 2): string {
if (bytes === 0) return "0 B";
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
}