完整横条显示并对容量尺寸单位优化自动识别

This commit is contained in:
Sun
2024-01-03 20:02:03 +08:00
parent fe967a9314
commit 8dfec7e4b7
2 changed files with 24 additions and 7 deletions
+8
View File
@@ -221,3 +221,11 @@ export async function copyToClipboard(text: string): Promise<boolean> {
}
}
}
export function bytesToSize(bytes: number) {
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB']
if (bytes === 0)
return '0B'
const i = parseInt(String(Math.floor(Math.log(bytes) / Math.log(1024))))
return `${(bytes / 1024 ** i).toFixed(1)} ${sizes[i]}`
}