INNER CODE UNIT · JavaScript
startDownload
xonotic/darkplaces · wasm/pre.js:41
function startDownload(localPath, remotePath) {
//
// Return a promise of a file download
//
Module['addRunDependency'](localPath); // Tell Emscripten about the dependency
return fetch(remotePath)
.then(response => {
return response.arrayBuffer();
})
.then(arrayBuffer => {
const buffer = new Uint8Array(arrayBuffer);
stream = FS.open("/game/" + localPath, "w");
FS.write(stream, buffer, 0, buffer.byteLength);
FS.close(stream);
console.log("Downloaded " + localPath);
Module['removeRunDependency'](localPath); // Tells Emscripten we've finished the download
});