MCPcopy Create free account
hub / github.com/ceifa/wasmoon / mountFileSync

Method mountFileSync

src/factory.ts:48–75  ·  view source on GitHub ↗

* Mounts a file in the Lua environment synchronously. * @param luaWasm - Lua WebAssembly module. * @param path - Path to the file in the Lua environment. * @param content - Content of the file to be mounted.

(luaWasm: LuaWasm, path: string, content: string | ArrayBufferView)

Source from the content-addressed store, hash-verified

46 * @param content - Content of the file to be mounted.
47 */
48 public mountFileSync(luaWasm: LuaWasm, path: string, content: string | ArrayBufferView): void {
49 const fileSep = path.lastIndexOf('/')
50 const file = path.substring(fileSep + 1)
51 const body = path.substring(0, path.length - file.length - 1)
52
53 if (body.length > 0) {
54 const parts = body.split('/').reverse()
55 let parent = ''
56
57 while (parts.length) {
58 const part = parts.pop()
59 if (!part) {
60 continue
61 }
62
63 const current = `${parent}/${part}`
64 try {
65 luaWasm.module.FS.mkdir(current)
66 } catch {
67 // ignore EEXIST
68 }
69
70 parent = current
71 }
72 }
73
74 luaWasm.module.FS.writeFile(path, content)
75 }
76
77 /**
78 * Creates a Lua engine with the specified options.

Callers 1

mountFileMethod · 0.95

Calls 1

popMethod · 0.80

Tested by

no test coverage detected