1
- import * as unzipper from 'unzipper' ;
2
1
import * as path from 'path' ;
3
2
import * as fs from 'fs-extra' ;
4
3
import { showAndLogErrorMessage , showAndLogWarningMessage , tmpDir } from '../helpers' ;
@@ -9,6 +8,7 @@ import { DownloadLink, createDownloadPath } from './download-link';
9
8
import { RemoteQuery } from './remote-query' ;
10
9
import { RemoteQueryFailureIndexItem , RemoteQueryResultIndex , RemoteQuerySuccessIndexItem } from './remote-query-result-index' ;
11
10
import { getErrorMessage } from '../pure/helpers-pure' ;
11
+ import { unzipFile } from '../pure/zip' ;
12
12
13
13
export const RESULT_INDEX_ARTIFACT_NAME = 'result-index' ;
14
14
@@ -110,10 +110,8 @@ export async function downloadArtifactFromLink(
110
110
const response = await octokit . request ( `GET ${ downloadLink . urlPath } /zip` , { } ) ;
111
111
112
112
const zipFilePath = createDownloadPath ( storagePath , downloadLink , 'zip' ) ;
113
- await saveFile ( `${ zipFilePath } ` , response . data as ArrayBuffer ) ;
114
113
115
- // Extract the zipped artifact.
116
- await unzipFile ( zipFilePath , extractedPath ) ;
114
+ await unzipBuffer ( response . data as ArrayBuffer , zipFilePath , extractedPath ) ;
117
115
}
118
116
return path . join ( extractedPath , downloadLink . innerFilePath || '' ) ;
119
117
}
@@ -300,20 +298,16 @@ async function downloadArtifact(
300
298
archive_format : 'zip' ,
301
299
} ) ;
302
300
const artifactPath = path . join ( tmpDir . name , `${ artifactId } ` ) ;
303
- await saveFile ( `${ artifactPath } .zip` , response . data as ArrayBuffer ) ;
304
- await unzipFile ( `${ artifactPath } .zip` , artifactPath ) ;
301
+ await unzipBuffer ( response . data as ArrayBuffer , `${ artifactPath } .zip` , artifactPath ) ;
305
302
return artifactPath ;
306
303
}
307
304
308
- async function saveFile ( filePath : string , data : ArrayBuffer ) : Promise < void > {
305
+ async function unzipBuffer ( data : ArrayBuffer , filePath : string , destinationPath : string ) : Promise < void > {
309
306
void logger . log ( `Saving file to ${ filePath } ` ) ;
310
307
await fs . writeFile ( filePath , Buffer . from ( data ) ) ;
311
- }
312
308
313
- async function unzipFile ( sourcePath : string , destinationPath : string ) {
314
309
void logger . log ( `Unzipping file to ${ destinationPath } ` ) ;
315
- const file = await unzipper . Open . file ( sourcePath ) ;
316
- await file . extract ( { path : destinationPath } ) ;
310
+ await unzipFile ( filePath , destinationPath ) ;
317
311
}
318
312
319
313
function getWorkflowError ( conclusion : string | null ) : string {
0 commit comments