From 368aad2d9ed80508195fd3700934e026d1106ed3 Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Fri, 8 Dec 2023 09:44:47 +1300 Subject: [PATCH] fix(cli): if the tiff is fully sparse dont print NaN --- packages/cli/src/commands/info.ts | 7 +++++-- packages/cli/src/util.bytes.ts | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/info.ts b/packages/cli/src/commands/info.ts index 024c83b0..4e990e9d 100644 --- a/packages/cli/src/commands/info.ts +++ b/packages/cli/src/commands/info.ts @@ -190,11 +190,14 @@ export const tiffTileStats: CliTableInfo = { }; for (const st of sizes) { if (st === 0) stats.empty++; + console.log(st, stats); stats.size += st; } - const empty = stats.empty > 0 ? ` (${c.blue('empty')}: ${stats.empty})` : ''; + if (stats.size === 0) return `${c.red('empty')} x${stats.empty}`; - const avg = stats.size / (sizes.length - stats.empty); + const empty = stats.empty > 0 ? ` (${c.red('empty')} x${stats.empty})` : ''; + + const avg = stats.size === 0 ? 0 : stats.size / (sizes.length - stats.empty); return toByteSizeString(stats.size) + ` (${c.blue('avg:')} ${toByteSizeString(avg)})` + empty; }, enabled: () => true, diff --git a/packages/cli/src/util.bytes.ts b/packages/cli/src/util.bytes.ts index 73a93905..feda9c2a 100644 --- a/packages/cli/src/util.bytes.ts +++ b/packages/cli/src/util.bytes.ts @@ -8,6 +8,7 @@ const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; * @param bytes byte count to convert */ export function toByteSizeString(bytes: number): string { + if (bytes === 0) return '0'; if (bytes === 1) return '1 Byte'; const i = Math.floor(Math.log(bytes) / Math.log(1024)); const output = bytes / Math.pow(1024, i);