@samitouri / QOSami-HFS / commits / d78bdd11

fix: (regression 0.47.0) "NaN" for 0-byte files

Massimo Melina committed Jul 21, 2023 at 22:48 UTC d78bdd115253c24e1ef4d5bac0a211e4a080c530
1 file changed +1 -1
shared/index.ts
+1 -1
@@ -33,7 +33,7 @@ const MULTIPLIERS = ['', 'K', 'M', 'G', 'T']
33 export function formatBytes(n: number, { post='B', k=1024, digits=NaN }={}) {
34 if (isNaN(Number(n)) || n < 0)
35 return ''
36 - const i = Math.floor(Math.log2(n) / Math.log2(k))
36 + const i = n && Math.floor(Math.log2(n) / Math.log2(k))
37 n /= k ** i
38 const nAsString = i && !isNaN(digits) ? n.toFixed(digits)
39 : _.round(n, isNaN(digits) ? (n >= 100 ? 0 : 1) : digits)