Skip to content

Commit

Permalink
fix(cli): if the tiff is fully sparse dont print NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha committed Dec 7, 2023
1 parent 5e90764 commit 368aad2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/cli/src/commands/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,14 @@ export const tiffTileStats: CliTableInfo<TiffImage> = {
};
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,
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/util.bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 368aad2

Please sign in to comment.