Skip to content

Commit

Permalink
fix(cli): correctly show "not loaded" when strings are not loaded (#1309
Browse files Browse the repository at this point in the history
)
  • Loading branch information
blacha authored Oct 15, 2024
1 parent f5262a3 commit fdbd4e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions packages/cli/src/commands/info.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fsa } from '@chunkd/fs';
import { Tag, TagOffset, Tiff, TiffImage, TiffTag, TiffTagGeo, TiffTagValueType, TiffVersion } from '@cogeotiff/core';
import { Tag, Tiff, TiffImage, TiffTag, TiffTagGeo, TiffTagValueType, TiffVersion } from '@cogeotiff/core';
import c from 'ansi-colors';
import { command, flag, option, optional, restPositionals } from 'cmd-ts';

Expand Down Expand Up @@ -221,17 +221,24 @@ function parseGdalMetadata(img: TiffImage): string[] | null {
.map((c) => c.trim());
}

function isLoaded(tag: Tag): boolean {
if (tag.type === 'offset' && tag.isLoaded === false) return false;
if (tag.type === 'lazy' && tag.value == null) return false;
return true;
}

function formatTag(tag: Tag): { key: string; value: string } {
const tagName = TiffTag[tag.id];
const tagDebug = `(${TiffTagValueType[tag.dataType]}${tag.count > 1 ? ' x' + tag.count : ''}`;
const key = `${c.dim(String(tag.id)).padEnd(7, ' ')} ${String(tagName)} ${c.dim(tagDebug)})`.padEnd(52, ' ');

if (!isLoaded(tag)) {
return { key, value: c.dim('Tag not Loaded, use --fetch-tags to force load') };
}

let complexType = '';
// Array of values that is not a string!
if (tag.count > 1 && tag.dataType !== TiffTagValueType.Ascii) {
if (tag.value == null || (tag as TagOffset).isLoaded === false) {
return { key, value: c.dim('Tag not Loaded, use --fetch-tags to force load') };
}
const val = [...(tag.value as number[])]; // Ensure the value is not a TypedArray
if (TagFormatters[tag.id]) {
complexType = ` - ${c.magenta(TagFormatters[tag.id](val) ?? '??')}`;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/read/tiff.tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface TagOffset extends TagBase {
type: 'offset';
/** Values of the offsets this is a sparse array unless @see {TagOffset.isLoaded} is true */
value: number[];
/** has all the values been read */
/** Have all the values been read */
isLoaded: boolean;
/** Raw buffer of the values for lazy decoding, as reading 100,000s of uint64s can take quite a long time */
view?: DataViewOffset;
Expand Down

0 comments on commit fdbd4e9

Please sign in to comment.