This commit is contained in:
李志鹏
2026-04-24 09:38:24 +08:00
parent 71cfef996d
commit 42c2817c2f
5 changed files with 13 additions and 10 deletions

View File

@@ -203,8 +203,8 @@ export function CountDown(time: number) {
* @returns {string} 格式化后的字符串
*/
export function FormatBytes(bytes, options: { decimals?: number, unitBig?: boolean } = {}) {
if (!bytes || isNaN(bytes)) return '0 B';
const { decimals = 2, unitBig = false } = options;
if (!bytes || isNaN(bytes)) return unitBig ? '0 B' : '0 b';
const k = 1024;
const sizes = unitBig ? ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] : ['b', 'kb', 'mb', 'gb', 'tb', 'pb', 'eb', 'zb', 'yb'];
const i = Math.floor(Math.log(bytes) / Math.log(k));