Commit

Download ZIP deflates sixteen files at a time, within a Worker's memory

syntaqxcommitted Parent0db826fBrowse files
1 file+11−20/1 viewed
+11−2
3232 const parts: Uint8Array[] = [];
3333 const central: Uint8Array[] = [];
3434 let offset = 0;
35− // Every file deflated at once: the streams interleave rather than queue.
36− const deflatedAll = await Promise.all(files.map((file) => (file.data.length > 0 ? deflate(file.data) : file.data)));
35+ // Sixteen files deflating at a time: quicker than one by one, without
36+ // every file's stream held at once.
37+ const deflatedAll: Uint8Array[] = new Array(files.length);
38+ let next = 0;
39+ const worker = async () => {
40+ for (let index = next++; index < files.length; index = next++) {
41+ const data = files[index]!.data;
42+ deflatedAll[index] = data.length > 0 ? await deflate(data) : data;
43+ }
44+ };
45+ await Promise.all(Array.from({ length: Math.min(16, files.length) }, worker));
3746 for (const [index, file] of files.entries()) {
3847 const name = encoder.encode(file.path);
3948 const crc = crc32(file.data);