Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend analyze command to provide subtree information #135

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/base/contentTypes/FileExtensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { ContentDataTypeRegistry } from "./ContentDataTypeRegistry";
import { ContentDataTypes } from "./ContentDataTypes";

/**
* Methods related to file extensions for the content data types
* that are defined in `ContentDataTypes`
*/
export class FileExtensions {
/**
* A dictionary of the content data types to the default
* file extensions (without dot)
*/
private static readonly knownFileExtensionsWithoutDot = {
[ContentDataTypes.CONTENT_TYPE_GLB]: "glb",
[ContentDataTypes.CONTENT_TYPE_B3DM]: "b3dm",
[ContentDataTypes.CONTENT_TYPE_I3DM]: "i3dm",
[ContentDataTypes.CONTENT_TYPE_CMPT]: "cmpt",
[ContentDataTypes.CONTENT_TYPE_PNTS]: "pnts",
[ContentDataTypes.CONTENT_TYPE_GEOM]: "geom",
[ContentDataTypes.CONTENT_TYPE_VCTR]: "vctr",
[ContentDataTypes.CONTENT_TYPE_SUBT]: "subt",
[ContentDataTypes.CONTENT_TYPE_PNG]: "png",
[ContentDataTypes.CONTENT_TYPE_JPEG]: "jpg",
[ContentDataTypes.CONTENT_TYPE_GIF]: "gif",
[ContentDataTypes.CONTENT_TYPE_GEOJSON]: "geojson",
[ContentDataTypes.CONTENT_TYPE_3TZ]: "3tz",
[ContentDataTypes.CONTENT_TYPE_GLTF]: "gltf",
[ContentDataTypes.CONTENT_TYPE_TILESET]: "json",
};

/**
* Returns the default extension (without dot) for files with the given
* content data type. If the given content data type is undefined or
* not known, then an empty string will be returned.
*
* @param type - The `ContentDataType`
* @returns The file extension
*/
static getDefaultFileExtension(type: string | undefined): string {
if (type === undefined) {
return "";
}
const result = FileExtensions.knownFileExtensionsWithoutDot[type];
if (result === undefined) {
return "";
}
return result;
}

/**
* Returns the default extension (without dot) for the given file
* data, depending on its content type. If the content data type
* cannot be determined or is not known, then an empty string will
* be returned.
*
* @param data - The file data
* @returns A promise to the file extension
*/
static async determineFileExtension(data: Buffer): Promise<string> {
const type = await ContentDataTypeRegistry.findType("", data);
return FileExtensions.getDefaultFileExtension(type);
}
}
1 change: 1 addition & 0 deletions src/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export * from "./contentTypes/ContentDataTypeEntry";
export * from "./contentTypes/ContentDataTypeRegistry";
export * from "./contentTypes/ContentDataTypes";
export * from "./contentTypes/LazyContentData";
export * from "./contentTypes/FileExtensions";

export * from "./io/FileResourceResolver";
export * from "./io/ResourceResolver";
Expand Down
Loading
Loading