@@ -67,31 +67,12 @@ import { resolveEmbedChrome, type RosViewerChrome, type RosViewerMode } from './
6767import { RosViewerLayoutProvider } from './RosViewerLayoutContext' ;
6868import type { RosViewExtension } from '@/core/extensions/types' ;
6969import { toast } from 'sonner' ;
70- import sqlWasmUrl from 'sql.js/dist/sql-wasm.wasm?url' ;
71- import hdf5WasmUrl from '@ioai/hdf5/wasm/ioai_hdf5.wasm?url' ;
72-
73- let sqlWasmBinaryPromise : Promise < ArrayBuffer > | null = null ;
74- let hdf5WasmBinaryPromise : Promise < ArrayBuffer > | null = null ;
75-
76- async function loadSqlWasmBinary ( ) : Promise < ArrayBuffer > {
77- sqlWasmBinaryPromise ??= fetch ( sqlWasmUrl ) . then ( ( response ) => {
78- if ( ! response . ok ) {
79- throw new Error ( `Failed to load SQL wasm: HTTP ${ response . status } ` ) ;
80- }
81- return response . arrayBuffer ( ) ;
82- } ) ;
83- return await sqlWasmBinaryPromise ;
84- }
85-
86- async function loadHdf5WasmBinary ( ) : Promise < ArrayBuffer > {
87- hdf5WasmBinaryPromise ??= fetch ( hdf5WasmUrl ) . then ( ( response ) => {
88- if ( ! response . ok ) {
89- throw new Error ( `Failed to load HDF5 wasm: HTTP ${ response . status } ` ) ;
90- }
91- return response . arrayBuffer ( ) ;
92- } ) ;
93- return await hdf5WasmBinaryPromise ;
94- }
70+ import {
71+ loadHdf5WasmBinary ,
72+ loadSqlWasmBinary ,
73+ loadZstdWasmBinary ,
74+ needsZstdWasmForWorker ,
75+ } from '@/infra/workers/preloadWorkerWasm' ;
9576
9677function extensionForDataset ( ds : DatasetItem ) : string | undefined {
9778 if ( ds . kind === 'file' && ds . file ) {
@@ -139,6 +120,7 @@ async function initializePlayerForDataset(
139120 typeof window !== 'undefined' && new URLSearchParams ( window . location . search ) . get ( 'workerPerf' ) === '1' ;
140121 const sqlWasmBinary = ext === 'db3' ? await loadSqlWasmBinary ( ) : undefined ;
141122 const hdf5WasmBinary = ext === 'hdf5' || ext === 'h5' ? await loadHdf5WasmBinary ( ) : undefined ;
123+ const zstdWasmBinary = needsZstdWasmForWorker ( ext ) ? await loadZstdWasmBinary ( ) : undefined ;
142124 if ( ds . kind === 'url' && ds . url ) {
143125 const init : Record < string , unknown > = {
144126 url : resolveBrowserHttpUrl ( ds . url ) ,
@@ -151,6 +133,9 @@ async function initializePlayerForDataset(
151133 if ( hdf5WasmBinary ) {
152134 init . hdf5WasmBinary = hdf5WasmBinary ;
153135 }
136+ if ( zstdWasmBinary ) {
137+ init . zstdWasmBinary = zstdWasmBinary ;
138+ }
154139 if (
155140 typeof ds . sizeBytes === 'number' &&
156141 Number . isFinite ( ds . sizeBytes ) &&
@@ -171,13 +156,15 @@ async function initializePlayerForDataset(
171156 workerPerf,
172157 autoDataQualityScan,
173158 ...( sqlWasmBinary ? { sqlWasmBinary } : { } ) ,
159+ ...( zstdWasmBinary ? { zstdWasmBinary } : { } ) ,
174160 } ) ;
175161 } else {
176162 await player . initialize ( {
177163 file : ds . file ,
178164 workerPerf,
179165 autoDataQualityScan,
180166 ...( hdf5WasmBinary ? { hdf5WasmBinary } : { } ) ,
167+ ...( zstdWasmBinary ? { zstdWasmBinary } : { } ) ,
181168 } ) ;
182169 }
183170 return ;
0 commit comments