Spaces:
Paused
Paused
Download node_modules/@huggingface/hub/src/utils/formatBytes.ts from ken-q/opencode-home: direct link, hf CLI and curl.
- Browser
- Download file 598 Bytes
-
https://huggingface.co/spaces/ken-q/opencode-home/resolve/main/node_modules/%40huggingface/hub/src/utils/formatBytes.ts
- Command line
-
hf download hf://spaces/ken-q/opencode-home/node_modules/@huggingface/hub/src/utils/formatBytes.ts
-
curl -L -o formatBytes.ts https://huggingface.co/spaces/ken-q/opencode-home/resolve/main/node_modules/%40huggingface/hub/src/utils/formatBytes.ts
598 Bytes
| /** | |
| * Format a byte count using SI units (multiples of 1000, e.g. `1.2 GB`). | |
| * | |
| * Negative or non-finite inputs are returned as `"<value> B"` without unit conversion. | |
| */ | |
| export function formatBytes(bytes: number): string { | |
| if (!Number.isFinite(bytes) || bytes < 0) { | |
| return `${bytes} B`; | |
| } | |
| const units = ["B", "kB", "MB", "GB", "TB", "PB"]; | |
| let value = bytes; | |
| let i = 0; | |
| while (value >= 1000 && i < units.length - 1) { | |
| value /= 1000; | |
| i++; | |
| } | |
| const formatted = i === 0 ? value.toString() : value.toFixed(value >= 100 ? 0 : value >= 10 ? 1 : 2); | |
| return `${formatted} ${units[i]}`; | |
| } | |