@@ -33,10 +33,10 @@ export type ExtractErrorType = 'CorruptZip' | 'Incomplete';
3333
3434export class ExtractError extends Error {
3535
36- readonly type : ExtractErrorType ;
36+ readonly type ? : ExtractErrorType ;
3737 readonly cause : Error ;
3838
39- constructor ( type : ExtractErrorType , cause : Error ) {
39+ constructor ( type : ExtractErrorType | undefined , cause : Error ) {
4040 let message = cause . message ;
4141
4242 switch ( type ) {
@@ -62,7 +62,7 @@ function toExtractError(err: Error): ExtractError {
6262 return err ;
6363 }
6464
65- let type : ExtractErrorType = void 0 ;
65+ let type : ExtractErrorType | undefined = void 0 ;
6666
6767 if ( / e n d o f c e n t r a l d i r e c t o r y r e c o r d s i g n a t u r e n o t f o u n d / . test ( err . message ) ) {
6868 type = 'CorruptZip' ;
@@ -94,7 +94,7 @@ function extractEntry(stream: Readable, fileName: string, mode: number, targetPa
9494
9595 try {
9696 istream = createWriteStream ( targetFileName , { mode } ) ;
97- istream . once ( 'close' , ( ) => c ( null ) ) ;
97+ istream . once ( 'close' , ( ) => c ( ) ) ;
9898 istream . once ( 'error' , e ) ;
9999 stream . once ( 'error' , e ) ;
100100 stream . pipe ( istream ) ;
@@ -105,7 +105,7 @@ function extractEntry(stream: Readable, fileName: string, mode: number, targetPa
105105}
106106
107107function extractZip ( zipfile : ZipFile , targetPath : string , options : IOptions , logService : ILogService , token : CancellationToken ) : Promise < void > {
108- let last = createCancelablePromise ( ( ) => Promise . resolve ( null ) ) ;
108+ let last = createCancelablePromise < void > ( ( ) => Promise . resolve ( ) ) ;
109109 let extractedEntriesCount = 0 ;
110110
111111 once ( token . onCancellationRequested ) ( ( ) => {
@@ -129,7 +129,7 @@ function extractZip(zipfile: ZipFile, targetPath: string, options: IOptions, log
129129 zipfile . once ( 'error' , e ) ;
130130 zipfile . once ( 'close' , ( ) => last . then ( ( ) => {
131131 if ( token . isCancellationRequested || zipfile . entryCount === extractedEntriesCount ) {
132- c ( null ) ;
132+ c ( ) ;
133133 } else {
134134 e ( new ExtractError ( 'Incomplete' , new Error ( nls . localize ( 'incompleteExtract' , "Incomplete. Found {0} of {1} entries" , extractedEntriesCount , zipfile . entryCount ) ) ) ) ;
135135 }
@@ -177,7 +177,13 @@ export interface IFile {
177177export function zip ( zipPath : string , files : IFile [ ] ) : Promise < string > {
178178 return new Promise < string > ( ( c , e ) => {
179179 const zip = new yazl . ZipFile ( ) ;
180- files . forEach ( f => f . contents ? zip . addBuffer ( typeof f . contents === 'string' ? Buffer . from ( f . contents , 'utf8' ) : f . contents , f . path ) : zip . addFile ( f . localPath , f . path ) ) ;
180+ files . forEach ( f => {
181+ if ( f . contents ) {
182+ zip . addBuffer ( typeof f . contents === 'string' ? Buffer . from ( f . contents , 'utf8' ) : f . contents , f . path ) ;
183+ } else if ( f . localPath ) {
184+ zip . addFile ( f . localPath , f . path ) ;
185+ }
186+ } ) ;
181187 zip . end ( ) ;
182188
183189 const zipStream = createWriteStream ( zipPath ) ;
0 commit comments