@@ -100,6 +100,9 @@ async function copyStream(
100100type UnzipProgress = {
101101 filesExtracted : number ;
102102 totalFiles : number ;
103+
104+ bytesExtracted : number ;
105+ totalBytes : number ;
103106} ;
104107
105108export type UnzipProgressCallback = ( progress : UnzipProgress ) => void ;
@@ -110,18 +113,21 @@ export type UnzipProgressCallback = (progress: UnzipProgress) => void;
110113 * @param zipFile
111114 * @param entry
112115 * @param rootDestinationPath
116+ * @return The number of bytes extracted.
113117 */
114118async function unzipFile (
115119 zipFile : ZipFile ,
116120 entry : ZipEntry ,
117121 rootDestinationPath : string ,
118- ) : Promise < void > {
122+ ) : Promise < number > {
119123 const path = join ( rootDestinationPath , entry . fileName ) ;
120124
121125 if ( / \/ $ / . test ( entry . fileName ) ) {
122126 // Directory file names end with '/'
123127
124128 await ensureDir ( path ) ;
129+
130+ return 0 ;
125131 } else {
126132 // Ensure the directory exists
127133 await ensureDir ( dirname ( path ) ) ;
@@ -139,6 +145,8 @@ async function unzipFile(
139145 } ) ;
140146
141147 await copyStream ( readable , writeStream ) ;
148+
149+ return entry . uncompressedSize ;
142150 }
143151}
144152
@@ -169,17 +177,30 @@ export async function unzipToDirectory(
169177
170178 let filesExtracted = 0 ;
171179 const totalFiles = entries . length ;
180+ let bytesExtracted = 0 ;
181+ const totalBytes = entries . reduce (
182+ ( total , entry ) => total + entry . uncompressedSize ,
183+ 0 ,
184+ ) ;
172185
173186 const reportProgress = ( ) => {
174187 progress ?.( {
175188 filesExtracted,
176189 totalFiles,
190+ bytesExtracted,
191+ totalBytes,
177192 } ) ;
178193 } ;
179194
180195 await taskRunner (
181196 entries . map ( ( entry ) => async ( ) => {
182- await unzipFile ( zipFile , entry , destinationPath ) ;
197+ const totalEntryBytesExtracted = await unzipFile (
198+ zipFile ,
199+ entry ,
200+ destinationPath ,
201+ ) ;
202+
203+ bytesExtracted += totalEntryBytesExtracted ;
183204
184205 filesExtracted ++ ;
185206 reportProgress ( ) ;
0 commit comments