2025-07-25 21:56:49 -04:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-10-08 01:23:17 +02:00
|
|
|
export const bytesToMB = (bytes: number): number => bytes / (1024 * 1024);
|
|
|
|
|
|
2026-01-27 17:21:53 +01:00
|
|
|
export const formatBytes = (bytes: number): string => {
|
2025-07-25 21:56:49 -04:00
|
|
|
const gb = bytes / (1024 * 1024 * 1024);
|
|
|
|
|
if (bytes < 1024 * 1024) {
|
|
|
|
|
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
|
|
|
}
|
|
|
|
|
if (bytes < 1024 * 1024 * 1024) {
|
2025-10-08 01:23:17 +02:00
|
|
|
return `${bytesToMB(bytes).toFixed(1)} MB`;
|
2025-07-25 21:56:49 -04:00
|
|
|
}
|
|
|
|
|
return `${gb.toFixed(2)} GB`;
|
|
|
|
|
};
|