2024-11-27 09:43:03 +01:00
|
|
|
export const Bytes = {
|
|
|
|
|
pretty(bytes: number) {
|
2024-11-27 11:06:02 +01:00
|
|
|
const sizes = ["B", "KB", "MB", "GB", "TB"];
|
2024-11-27 09:43:03 +01:00
|
|
|
if (bytes == 0) {
|
2024-11-27 11:06:02 +01:00
|
|
|
return "0 B";
|
2024-11-27 09:43:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)).toString());
|
2024-08-22 17:41:44 +02:00
|
|
|
|
2024-11-27 09:43:03 +01:00
|
|
|
if (i == 0) {
|
2024-11-27 11:06:02 +01:00
|
|
|
return bytes.toFixed(1) + " " + sizes[i];
|
2024-11-27 09:43:03 +01:00
|
|
|
}
|
2024-08-22 17:41:44 +02:00
|
|
|
|
2024-11-27 09:43:03 +01:00
|
|
|
return (bytes / Math.pow(1024, i)).toFixed(1) + " " + sizes[i];
|
2024-08-22 17:41:44 +02:00
|
|
|
}
|
|
|
|
|
|
2024-11-27 09:43:03 +01:00
|
|
|
}
|