Skip to content

Commit 31f6f47

Browse files
committed
feat(load-emscripten-module-node): load zstd compressed wasm
1 parent 2e24856 commit 31f6f47

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

packages/core/typescript/itk-wasm/src/pipeline/internal/load-emscripten-module-node.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import fs from 'fs'
22
import EmscriptenModule from '../itk-wasm-emscripten-module.js'
33
import { pathToFileURL } from 'url'
4+
import { ZSTDDecoder } from '@thewtex/zstddec'
45

5-
async function loadEmscriptenModuleNode (
6+
const zstdDecoder = new ZSTDDecoder()
7+
await zstdDecoder.init()
8+
9+
async function loadEmscriptenModuleNode(
610
modulePath: string
711
): Promise<EmscriptenModule> {
812
let modulePrefix = modulePath
@@ -12,8 +16,12 @@ async function loadEmscriptenModuleNode (
1216
if (modulePath.endsWith('.wasm')) {
1317
modulePrefix = modulePath.substring(0, modulePath.length - 5)
1418
}
15-
const wasmBinaryPath = `${modulePrefix}.wasm`
16-
const wasmBinary = fs.readFileSync(wasmBinaryPath)
19+
if (modulePath.endsWith('.wasm.zst')) {
20+
modulePrefix = modulePath.substring(0, modulePath.length - 9)
21+
}
22+
const compressedWasmBinaryPath = `${modulePrefix}.wasm.zst`
23+
const compressedWasmBinary = fs.readFileSync(compressedWasmBinaryPath)
24+
const wasmBinary = zstdDecoder.decode(new Uint8Array(compressedWasmBinary))
1725
const fullModulePath = pathToFileURL(`${modulePrefix}.js`).href
1826
const result = await import(
1927
/* webpackIgnore: true */ /* @vite-ignore */ fullModulePath

0 commit comments

Comments
 (0)