This commit is contained in:
2026-07-07 21:08:52 +02:00
commit 4c20cfc716
2613 changed files with 318021 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
const {parentPort} = require('worker_threads')
const fs = require('fs')
const ops = {
writeFile(args) {
fs.writeFileSync(args.path, args.data, args.encoding || 'utf8')
}
}
parentPort.on('message', (msg) => {
const {op, args, signal} = msg
const view = new Int32Array(signal)
try {
const handler = ops[op]
if (!handler) throw new Error(`Unknown op: ${op}`)
handler(args)
Atomics.store(view, 0, 1)
} catch(e) {
console.error(`[fs-worker] ${op} error:`, e.message)
Atomics.store(view, 0, -1)
}
Atomics.notify(view, 0)
})

View File

@@ -0,0 +1,18 @@
const {Worker} = require('worker_threads')
const pathModule = require('path')
const worker = new Worker(pathModule.join(GetResourcePath(GetCurrentResourceName()), 'utils', 'wrapper', 'sv_fs_worker.js'))
const signal = new SharedArrayBuffer(4)
function workerCall(op, args) {
const view = new Int32Array(signal)
Atomics.store(view, 0, 0)
worker.postMessage({op, args, signal})
Atomics.wait(view, 0, 0)
return Atomics.load(view, 0) === 1
}
exports('SaveResourceFile', (filePath, data) => {
if (!filePath || !data) return false
return workerCall('writeFile', {path: filePath, data})
})