@@ -109,7 +109,7 @@ async function copyStream(
109109 * @param entry
110110 * @param rootDestinationPath
111111 */
112- export async function unzipFile (
112+ async function unzipFile (
113113 zipFile : ZipFile ,
114114 entry : ZipEntry ,
115115 rootDestinationPath : string ,
@@ -141,16 +141,18 @@ export async function unzipFile(
141141}
142142
143143/**
144- * Sequentially unzips all files from a zip archive. Please use
145- * `unzipToDirectoryConcurrently` if you can. This function is only
146- * provided because Jest cannot import `p-queue` .
144+ * Unzips all files from a zip archive. Please use
145+ * `unzipToDirectoryConcurrently` or `unzipToDirectorySequentially` instead
146+ * of this function .
147147 *
148148 * @param archivePath
149149 * @param destinationPath
150+ * @param taskRunner A function that runs the tasks (either sequentially or concurrently).
150151 */
151- export async function unzipToDirectorySequentially (
152+ export async function unzipToDirectory (
152153 archivePath : string ,
153154 destinationPath : string ,
155+ taskRunner : ( tasks : Array < ( ) => Promise < void > > ) => Promise < void > ,
154156) : Promise < void > {
155157 const zipFile = await openZip ( archivePath , {
156158 autoClose : false ,
@@ -161,10 +163,29 @@ export async function unzipToDirectorySequentially(
161163 try {
162164 const entries = await readZipEntries ( zipFile ) ;
163165
164- for ( const entry of entries ) {
165- await unzipFile ( zipFile , entry , destinationPath ) ;
166- }
166+ await taskRunner (
167+ entries . map ( ( entry ) => ( ) => unzipFile ( zipFile , entry , destinationPath ) ) ,
168+ ) ;
167169 } finally {
168170 zipFile . close ( ) ;
169171 }
170172}
173+
174+ /**
175+ * Sequentially unzips all files from a zip archive. Please use
176+ * `unzipToDirectoryConcurrently` if you can. This function is only
177+ * provided because Jest cannot import `p-queue`.
178+ *
179+ * @param archivePath
180+ * @param destinationPath
181+ */
182+ export async function unzipToDirectorySequentially (
183+ archivePath : string ,
184+ destinationPath : string ,
185+ ) : Promise < void > {
186+ return unzipToDirectory ( archivePath , destinationPath , async ( tasks ) => {
187+ for ( const task of tasks ) {
188+ await task ( ) ;
189+ }
190+ } ) ;
191+ }
0 commit comments