diff --git a/bin/pack-resources.js b/bin/pack-resources.js index 00287c0..7284abc 100644 --- a/bin/pack-resources.js +++ b/bin/pack-resources.js @@ -67,9 +67,17 @@ for (const dirent of await readdir(wasmDirectory, { withFileTypes: true })) { output += `\ }); -const filesystem = async (fetch) => ({ +const filesystem = async (fetch) => { + var chunks = []; `; +function* chunks(data, length) { + while (data.length != 0) { + yield data.subarray(0, length); + data = data.subarray(length); + } +} + if (shareDirectory !== undefined) { const tarEntries = []; async function archivePath(pathName) { @@ -89,19 +97,25 @@ if (shareDirectory !== undefined) { } await archivePath(shareDirectory); const tarData = createTar(tarEntries); - const tarFilePath = resourceFilePath.replace(/\.js$/, '.tar'); - await writeFile(tarFilePath, tarData); - - const tarFileName = tarFilePath.replace(/^.+\//, ''); + var i = 0; + for(const chunk of chunks(tarData, 50*1024*1024)) { + const tarFileChunkPath = resourceFilePath.replace(/\.js$/, `.${i}.tar`); + await writeFile(tarFileChunkPath, chunk); + const tarFileChunkName = tarFileChunkPath.replace(/^.+\//, ''); + output += `\ + chunks.push(await ${await fetchExpr(tarFileChunkPath, `./${tarFileChunkName}`)}.then((resp) => resp.arrayBuffer())); +` + i += 1; + } output += `\ - ${JSON.stringify(shareRoot)}: await ${await fetchExpr(tarFilePath, `./${tarFileName}`)} - .then((resp) => resp.arrayBuffer()) - .then(unpackTarFilesystem) + return { + ${JSON.stringify(shareRoot)}: await new Blob(chunks).arrayBuffer().then(unpackTarFilesystem) + }; `; } output += `\ -}); +}; const totalSize = ${totalSize};