feat FileManager

This commit is contained in:
jxxghp
2023-08-26 11:00:33 +08:00
parent 5db4d97568
commit 4681c947c7
11 changed files with 588 additions and 951 deletions

View File

@@ -95,3 +95,17 @@ export function parseDate(dateString: string): Date {
return new Date(year, month - 1, day)
}
// 文件大小格式化
export function formatBytes(bytes: number, decimals = 2) {
if (bytes === 0)
return '0 bytes'
const k = 1024
const dm = decimals < 0 ? 0 : decimals
const sizes = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
const i = Math.floor(Math.log(bytes) / Math.log(k))
return `${parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`
}