serialize file creation unzipping
Massimo Melina committed
Jun 1, 2023 at 11:54 UTC
304f021ae84c64686c8ade8001e37ec00f3c3e22
1 file changed
+11
-11
src/util-files.ts
+11
-11
@@ -111,17 +111,17 @@ export async function unzip(stream: Readable, cb: (path: string) => false | stri
111
return new Promise(resolve =>
112
stream.pipe(unzipper.Parse())
113
.on('end', () => pending.then(resolve))
114
- .on('entry', async (entry: any) => {
115
- const { path, type } = entry
116
- const dest = cb(path)
117
- if (!dest || type !== 'File')
118
- return entry.autodrain()
119
- await pending // don't overlap writings
120
- console.debug('unzip', dest)
121
- await prepareFolder(dest)
122
- const thisFile = entry.pipe(createWriteStream(dest))
123
- pending = once(thisFile, 'finish')
124
- })
114
+ .on('entry', (entry: any) =>
115
+ pending = pending.then(async () => { // don't overlap writings
116
+ const { path, type } = entry
117
+ const dest = cb(path)
118
+ if (!dest || type !== 'File')
119
+ return entry.autodrain()
120
+ console.debug('unzip', dest)
121
+ await prepareFolder(dest)
122
+ const thisFile = entry.pipe(createWriteStream(dest))
123
+ await once(thisFile, 'finish')
124
+ }) )
125
)
126
}
127