Skip to content

Commit

Permalink
feat(io): expose itk-wasm setPipelineBaseUrl setPipelineWorkerUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Jul 12, 2024
1 parent e615a3c commit 0871fbb
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changeset/weak-lies-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@itk-viewer/blosc-zarr': minor
'@itk-viewer/io': minor
---

Export itk-wasm pipeline url setting functions.
7 changes: 6 additions & 1 deletion packages/blosc-zarr/bloscZarrDecompress.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@

export function bloscZarrDecompress(chunkData: Array<{data: ArrayBuffer, metadata: any}>): Promise<Array<ArrayBuffer>>;
export function bloscZarrDecompress(chunkData: Array<{data: ArrayBuffer, metadata: any}>): Promise<Array<ArrayBuffer>>;

export function getPipelinesBaseUrl(): string;
export function setPipelinesBaseUrl(url: string): void;
export function getPipelineWorkerUrl(): string;
export function setPipelineWorkerUrl(url: string): void;
13 changes: 7 additions & 6 deletions packages/blosc-zarr/bloscZarrDecompress.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {
runPipeline,
InterfaceTypes,
WorkerPool,
import { runPipeline, InterfaceTypes, WorkerPool } from 'itk-wasm';
import { getSize } from '@itk-viewer/utils/dtypeUtils.js';
import { getPipelinesBaseUrl, getPipelineWorkerUrl } from './pipeline-urls.js';
export {
getPipelinesBaseUrl,
setPipelinesBaseUrl,
getPipelineWorkerUrl,
} from 'itk-wasm';
import { getSize } from '@itk-viewer/utils/dtypeUtils.js';
setPipelineWorkerUrl,
} from './pipeline-urls.js';

const cores = navigator.hardwareConcurrency ? navigator.hardwareConcurrency : 4;
const numberOfWorkers = cores + Math.floor(Math.sqrt(cores));
Expand Down
41 changes: 41 additions & 0 deletions packages/blosc-zarr/pipeline-urls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { getPipelinesBaseUrl as itkWasmGetPipelinesBaseUrl, getPipelineWorkerUrl as itkWasmGetPipelineWorkerUrl } from "itk-wasm";
import { version } from "./version.js";

let pipelinesBaseUrl
let defaultPipelinesBaseUrl =
`https://cdn.jsdelivr.net/npm/@itk-viewer/blosc-zarr@${version}/`;

export function setPipelinesBaseUrl(baseUrl) {
pipelinesBaseUrl = baseUrl;
}

export function getPipelinesBaseUrl() {
if (typeof pipelinesBaseUrl !== "undefined") {
return pipelinesBaseUrl;
}
const itkWasmPipelinesBaseUrl = itkWasmGetPipelinesBaseUrl();
if (typeof itkWasmPipelinesBaseUrl !== "undefined") {
return itkWasmPipelinesBaseUrl;
}
return defaultPipelinesBaseUrl;
}

let pipelineWorkerUrl
// Use the version shipped with an app's bundler
const defaultPipelineWorkerUrl = null

export function setPipelineWorkerUrl (workerUrl) {
pipelineWorkerUrl = workerUrl
}

export function getPipelineWorkerUrl () {
if (typeof pipelineWorkerUrl !== 'undefined') {
return pipelineWorkerUrl
}
const itkWasmPipelineWorkerUrl = itkWasmGetPipelineWorkerUrl()
if (typeof itkWasmPipelineWorkerUrl !== 'undefined') {
return itkWasmPipelineWorkerUrl
}
return defaultPipelineWorkerUrl
}

1 change: 1 addition & 0 deletions packages/blosc-zarr/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const version = "0.1.3";
13 changes: 13 additions & 0 deletions packages/io/src/pipeline-urls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export {
getPipelinesBaseUrl,
setPipelinesBaseUrl,
getPipelineWorkerUrl,
setPipelineWorkerUrl,
} from 'itk-wasm';

export {
getPipelinesBaseUrl as bloscZarrGetPipelinesBaseUrl,
setPipelinesBaseUrl as bloscZarrSetPipelinesBaseUrl,
getPipelineWorkerUrl as bloscZarrGetPipelineWorkerUrl,
setPipelineWorkerUrl as bloscZarrSetPipelineWorkerUrl,
} from '@itk-viewer/blosc-zarr/bloscZarrDecompress.js';

0 comments on commit 0871fbb

Please sign in to comment.