@@ -67,9 +67,17 @@ for (const dirent of await readdir(wasmDirectory, { withFileTypes: true })) {
6767output += `\
6868});
6969
70- const filesystem = async (fetch) => ({
70+ const filesystem = async (fetch) => {
71+ var chunks = [];
7172` ;
7273
74+ function * chunks ( data , length ) {
75+ while ( data . length != 0 ) {
76+ yield data . subarray ( 0 , length ) ;
77+ data = data . subarray ( length ) ;
78+ }
79+ }
80+
7381if ( shareDirectory !== undefined ) {
7482 const tarEntries = [ ] ;
7583 async function archivePath ( pathName ) {
@@ -89,19 +97,25 @@ if (shareDirectory !== undefined) {
8997 }
9098 await archivePath ( shareDirectory ) ;
9199 const tarData = createTar ( tarEntries ) ;
92- const tarFilePath = resourceFilePath . replace ( / \. j s $ / , '.tar' ) ;
93- await writeFile ( tarFilePath , tarData ) ;
94-
95- const tarFileName = tarFilePath . replace ( / ^ .+ \/ / , '' ) ;
100+ var i = 0 ;
101+ for ( const chunk of chunks ( tarData , 50 * 1024 * 1024 ) ) {
102+ const tarFileChunkPath = resourceFilePath . replace ( / \. j s $ / , `.${ i } .tar` ) ;
103+ await writeFile ( tarFileChunkPath , chunk ) ;
104+ const tarFileChunkName = tarFileChunkPath . replace ( / ^ .+ \/ / , '' ) ;
105+ output += `\
106+ chunks.push(await ${ await fetchExpr ( tarFileChunkPath , `./${ tarFileChunkName } ` ) } .then((resp) => resp.arrayBuffer()));
107+ `
108+ i += 1 ;
109+ }
96110 output += `\
97- ${ JSON . stringify ( shareRoot ) } : await ${ await fetchExpr ( tarFilePath , `./ ${ tarFileName } ` ) }
98- .then((resp) => resp .arrayBuffer())
99- .then(unpackTarFilesystem)
111+ return {
112+ ${ JSON . stringify ( shareRoot ) } : await new Blob(chunks) .arrayBuffer().then(unpackTarFilesystem )
113+ };
100114` ;
101115}
102116
103117output += `\
104- }) ;
118+ };
105119
106120const totalSize = ${ totalSize } ;
107121
0 commit comments