fix(dashboard): render Ki-range sizes as Ki, not raw bytes

humanizeBytes branched on Ti/Gi/Mi and then fell through to a raw
byte count, so every value between 1KiB and 1MiB printed as e.g.
"524288B" instead of "512Ki". Add the missing Ki branch, formatted
without decimals like the Mi branch above it.

Fixes #3105

Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
This commit is contained in:
Myasnikov Daniil authored and Aleksei Sviridkin committed 2026-10-07 05:03:17 +03:00
1 parent d2e3eb4f82
commit fa3db545b9
2 files changed
+6

No files matched your search

@@ -101,6 +101,11 @@ describe("humanizeBytes", () => {
expect(humanizeBytes(1023)).toBe("1023B")
})
it("formats kilobytes as Ki without decimals", () => {
expect(humanizeBytes(1024)).toBe("1Ki")
expect(humanizeBytes(512 * 1024)).toBe("512Ki")
})
it("formats megabytes as Mi without decimals", () => {
expect(humanizeBytes(1024 ** 2)).toBe("1Mi")
})
@@ -33,6 +33,7 @@ export function humanizeBytes(bytes: number): string {
if (bytes >= 1024 ** 4) return `${(bytes / 1024 ** 4).toFixed(1)}Ti`
if (bytes >= 1024 ** 3) return `${(bytes / 1024 ** 3).toFixed(1)}Gi`
if (bytes >= 1024 ** 2) return `${(bytes / 1024 ** 2).toFixed(0)}Mi`
if (bytes >= 1024) return `${(bytes / 1024).toFixed(0)}Ki`
return `${bytes}B`
}