fix: couldn't print 1000TB+ file size
Massimo Melina committed
Sep 26, 2024 at 09:49 UTC
b30c5e7d9e63d5710308fbf6bb104fa22b5c7e84
1 file changed
+1
-1
src/cross.ts
+1
-1
@@ -88,7 +88,7 @@ const MULTIPLIERS = ['', 'K', 'M', 'G', 'T']
88
export function formatBytes(n: number, { post='B', k=1024, digits=NaN, sep=' ' }={}) {
89
if (isNaN(Number(n)) || n < 0)
90
return ''
91
- const i = n && Math.floor(Math.log2(n) / Math.log2(k))
91
+ const i = n && Math.min(MULTIPLIERS.length - 1, Math.floor(Math.log2(n) / Math.log2(k)))
92
n /= k ** i
93
const nAsString = i && !isNaN(digits) ? n.toFixed(digits)
94
: _.round(n, isNaN(digits) ? (n >= 100 ? 0 : 1) : digits)