1- import * as unzipper from 'unzipper' ;
21import * as path from 'path' ;
32import * as fs from 'fs-extra' ;
43import { showAndLogErrorMessage , showAndLogWarningMessage , tmpDir } from '../helpers' ;
@@ -9,6 +8,7 @@ import { DownloadLink, createDownloadPath } from './download-link';
98import { RemoteQuery } from './remote-query' ;
109import { RemoteQueryFailureIndexItem , RemoteQueryResultIndex , RemoteQuerySuccessIndexItem } from './remote-query-result-index' ;
1110import { getErrorMessage } from '../pure/helpers-pure' ;
11+ import { unzipFile } from '../pure/zip' ;
1212
1313export const RESULT_INDEX_ARTIFACT_NAME = 'result-index' ;
1414
@@ -110,10 +110,8 @@ export async function downloadArtifactFromLink(
110110 const response = await octokit . request ( `GET ${ downloadLink . urlPath } /zip` , { } ) ;
111111
112112 const zipFilePath = createDownloadPath ( storagePath , downloadLink , 'zip' ) ;
113- await saveFile ( `${ zipFilePath } ` , response . data as ArrayBuffer ) ;
114113
115- // Extract the zipped artifact.
116- await unzipFile ( zipFilePath , extractedPath ) ;
114+ await unzipBuffer ( response . data as ArrayBuffer , zipFilePath , extractedPath ) ;
117115 }
118116 return path . join ( extractedPath , downloadLink . innerFilePath || '' ) ;
119117}
@@ -300,20 +298,16 @@ async function downloadArtifact(
300298 archive_format : 'zip' ,
301299 } ) ;
302300 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 ) ;
305302 return artifactPath ;
306303}
307304
308- async function saveFile ( filePath : string , data : ArrayBuffer ) : Promise < void > {
305+ async function unzipBuffer ( data : ArrayBuffer , filePath : string , destinationPath : string ) : Promise < void > {
309306 void logger . log ( `Saving file to ${ filePath } ` ) ;
310307 await fs . writeFile ( filePath , Buffer . from ( data ) ) ;
311- }
312308
313- async function unzipFile ( sourcePath : string , destinationPath : string ) {
314309 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 ) ;
317311}
318312
319313function getWorkflowError ( conclusion : string | null ) : string {
0 commit comments