Skip to content
Open
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
9 changes: 0 additions & 9 deletions src/core/gzipBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ import untar from "js-untar";
import { stripLeadingDotSlash } from "./stringOps.js";
import { MODULE_JS_FILE_EXTENSION, WASM_FILE_EXTENSION } from "./constants.js";

/**
* Check if provided URL points to a gzip bundle
* @param {string} url
* @returns {boolean}
*/
export function isGzipBundle(url) {
return typeof url === "string" && url.endsWith(".gz");
}

/**
* Fetch gzip bundle from provided URL
* @param {string} url
Expand Down
12 changes: 10 additions & 2 deletions src/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ import { createFuture } from "./core/future";
* If vtkWebAssemblyInterface.mjs is already loaded as a script,
* this will be ignored.
* @param {Object} config
* @param {string} [wasmBaseName] - (default is `"vtk"`) base name of the wasm bundle to load. e.g., `"vtk"` or `"addon"` will
* look for vtkWebAssembly.mjs or addonWebAssembly.mjs in the wasmBaseURL.
* @param {boolean} [urlIsGzipBundle] - (default is `true`) specifies whether the resource at `wasmBaseURL` is a Gzip archive.
*
* @returns the vtk namespace for creating VTK objects.
*/
export async function createNamespace(url, config = {}, wasmBaseName = "vtk") {
export async function createNamespace(
url,
config = {},
wasmBaseName = "vtk",
urlIsGzipBundle = true,
) {
const loader = new VtkWASMLoader();
await loader.load(url || "loaded-module", config, wasmBaseName);
await loader.load(url || "loaded-module", config, wasmBaseName, urlIsGzipBundle);
return loader.createNamespace();
}

Expand Down
8 changes: 5 additions & 3 deletions src/wasmLoader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extractFilesFromGzipBundle, fetchGzipBundle, isGzipBundle } from "./core/gzipBundle";
import { extractFilesFromGzipBundle, fetchGzipBundle } from "./core/gzipBundle";
import { createEmscriptenConfig, normalizeConfig, validateConfig } from "./core/configManager";
import { DEFAULT_CONFIG, MIME_TYPES } from "./core/constants";
import { createScriptURL, loadWebAssemblyModuleFromExistingScript, loadWebAssemblyModuleFromScript } from "./core/scriptLoader";
Expand Down Expand Up @@ -42,13 +42,15 @@ export class VtkWASMLoader {
*
* @param {string} wasmBaseURL
* @param {object} config - for WASM runtime creation.
* @param {string} wasmBaseName - (default is "vtk") base name of the wasm bundle to load. e.g., "vtk" or "addon" will
* @param {string} wasmBaseName - (default is `"vtk"`) base name of the wasm bundle to load. e.g., `"vtk"` or `"addon"` will
* look for vtkWebAssembly.mjs or addonWebAssembly.mjs in the wasmBaseURL.
* @param {boolean} [urlIsGzipBundle] - (default is `true`) specifies whether the resource at `wasmBaseURL` is a Gzip archive.
*/
async load(
wasmBaseURL,
config = DEFAULT_CONFIG,
wasmBaseName = "vtk",
urlIsGzipBundle = true,
) {
if (this.#loaded) {
return;
Expand All @@ -67,7 +69,7 @@ export class VtkWASMLoader {

let wasmFile = null;
if (!window.createVTKWASM) {
if (isGzipBundle(wasmBaseURL)) {
if (urlIsGzipBundle) {
let gzipArrayBuffer;
let javaScriptBlobURL = null;
try {
Expand Down