MCPcopy Create free account
hub / github.com/firebase/firebase-tools / formatFilesize

Function formatFilesize

src/utils.ts:1136–1143  ·  view source on GitHub ↗
(bytes: number, decimals = 2)

Source from the content-addressed store, hash-verified

1134 * Formats a byte count into a human-readable file size string.
1135 */
1136export function formatFilesize(bytes: number, decimals = 2): string {
1137 if (bytes <= 0) return "0 Bytes";
1138 const k = 1024;
1139 const dm = decimals < 0 ? 0 : decimals;
1140 const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
1141 const i = Math.min(Math.floor(Math.log(bytes) / Math.log(k)), sizes.length - 1);
1142 return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
1143}
1144
1145export type Limit = <T>(fn: () => Promise<T>) => Promise<T>;
1146

Callers 1

archiveDirectoryFunction · 0.90

Calls 1

logMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…