Skip to content

Commit

Permalink
feat(EmscriptenModule): Add mountDir, unmountDir
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Jun 6, 2023
1 parent 4775202 commit 20d4911
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/emscripten-module/itkJSPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,40 @@ Module.unmountContainingDir = function (filePath) {
FS.unmount(containingDir)
}

/** Mount a containing directory in the
* Emscripten virtual filesystem. Only relevant when within the Node.js
* environment. */
Module.mountDir = function (dir) {
if (!ENVIRONMENT_IS_NODE) {
return
}
// If the root, abort
if (dir === '/') {
throw new Error('Cannot mount root directory')
}

var currentDir = '/'
var splitDir = dir.split(path.sep)
for (var ii = 1; ii < splitDir.length; ii++) {
currentDir += splitDir[ii]
if (!FS.analyzePath(currentDir).exists) {
FS.mkdir(currentDir)
}
currentDir += '/'
}
FS.mount(NODEFS, { root: dir }, currentDir)
return currentDir
}

/** Unmount its a directory in the
* Emscripten virtual filesystem. */
Module.unmountDir = function (dir) {
if (!ENVIRONMENT_IS_NODE) {
return
}
FS.unmount(dir)
}

Module.fs_mkdirs = function (dirs) {
var currentDir = '/'
var splitDirs = dirs.split('/')
Expand Down

0 comments on commit 20d4911

Please sign in to comment.