Fix engine.js preloadFile() with directories

(cherry picked from commit 6f1bddf4b5)
This commit is contained in:
Leon Krause 2018-03-27 09:14:03 +02:00 committed by Hein-Pieter van Braam
parent 0f6626977b
commit 78b44eab0a
1 changed files with 13 additions and 3 deletions

View File

@ -1,3 +1,4 @@
exposedLibs['PATH'] = PATH;
exposedLibs['FS'] = FS; exposedLibs['FS'] = FS;
return Module; return Module;
}, },
@ -96,14 +97,14 @@
} }
if (pathOrBuffer instanceof Uint8Array) { if (pathOrBuffer instanceof Uint8Array) {
preloadedFiles.push({ preloadedFiles.push({
name: bufferFilename, path: bufferFilename,
buffer: pathOrBuffer buffer: pathOrBuffer
}); });
return Promise.resolve(); return Promise.resolve();
} else if (typeof pathOrBuffer === 'string') { } else if (typeof pathOrBuffer === 'string') {
return loadPromise(pathOrBuffer, preloadProgressTracker).then(function(xhr) { return loadPromise(pathOrBuffer, preloadProgressTracker).then(function(xhr) {
preloadedFiles.push({ preloadedFiles.push({
name: pathOrBuffer, path: pathOrBuffer,
buffer: xhr.response buffer: xhr.response
}); });
}); });
@ -178,7 +179,16 @@
this.rtenv.thisProgram = executableName || getBaseName(basePath); this.rtenv.thisProgram = executableName || getBaseName(basePath);
preloadedFiles.forEach(function(file) { preloadedFiles.forEach(function(file) {
LIBS.FS.createDataFile('/', file.name, new Uint8Array(file.buffer), true, true, true); var dir = LIBS.PATH.dirname(file.path);
try {
LIBS.FS.stat(dir);
} catch (e) {
if (e.code !== 'ENOENT') {
throw e;
}
LIBS.FS.mkdirTree(dir);
}
LIBS.FS.createDataFile('/', file.path, new Uint8Array(file.buffer), true, true, true);
}, this); }, this);
preloadedFiles = null; preloadedFiles = null;