@@ -67,9 +67,20 @@ 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+ var rest = data ;
76+ var chunks = [ ] ;
77+ while ( rest . length != 0 ) {
78+ chunks . push ( rest . subarray ( 0 , length ) ) ;
79+ rest = rest . subarray ( length ) ;
80+ }
81+ return chunks ;
82+ }
83+
7384if ( shareDirectory !== undefined ) {
7485 const tarEntries = [ ] ;
7586 async function archivePath ( pathName ) {
@@ -89,19 +100,25 @@ if (shareDirectory !== undefined) {
89100 }
90101 await archivePath ( shareDirectory ) ;
91102 const tarData = createTar ( tarEntries ) ;
92- const tarFilePath = resourceFilePath . replace ( / \. j s $ / , '.tar' ) ;
93- await writeFile ( tarFilePath , tarData ) ;
94-
95- const tarFileName = tarFilePath . replace ( / ^ .+ \/ / , '' ) ;
103+ var i = 0 ;
104+ for ( const chunk of chunks ( tarData , 50 * 1024 * 1024 ) ) {
105+ const tarFileChunkPath = resourceFilePath . replace ( / \. j s $ / , `.${ i } .tar` ) ;
106+ await writeFile ( tarFileChunkPath , chunk ) ;
107+ const tarFileChunkName = tarFileChunkPath . replace ( / ^ .+ \/ / , '' ) ;
108+ output += `\
109+ chunks.push(await ${ await fetchExpr ( tarFileChunkPath , `./${ tarFileChunkName } ` ) } .then((resp) => resp.arrayBuffer()));
110+ `
111+ i += 1 ;
112+ }
96113 output += `\
97- ${ JSON . stringify ( shareRoot ) } : await ${ await fetchExpr ( tarFilePath , `./ ${ tarFileName } ` ) }
98- .then((resp) => resp .arrayBuffer())
99- .then(unpackTarFilesystem)
114+ return {
115+ ${ JSON . stringify ( shareRoot ) } : await new Blob(chunks) .arrayBuffer().then(unpackTarFilesystem )
116+ };
100117` ;
101118}
102119
103120output += `\
104- }) ;
121+ };
105122
106123const totalSize = ${ totalSize } ;
107124
0 commit comments