22 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33 * SPDX-License-Identifier: Apache-2.0
44 */
5- import admZip from 'adm-zip'
65import * as vscode from 'vscode'
76import path from 'path'
87import { tempDirPath , testGenerationLogsDir } from '../../shared/filesystemUtilities'
@@ -25,6 +24,7 @@ import { ChildProcess, ChildProcessOptions } from '../../shared/utilities/proces
2524import { ProjectZipError } from '../../amazonqTest/error'
2625import { removeAnsi } from '../../shared/utilities/textUtilities'
2726import { normalize } from '../../shared/utilities/pathUtils'
27+ import { ZipStream } from '../../shared/utilities/zipStream'
2828
2929export interface ZipMetadata {
3030 rootDir : string
@@ -109,7 +109,7 @@ export class ZipUtil {
109109 if ( ! uri ) {
110110 throw new NoActiveFileError ( )
111111 }
112- const zip = new admZip ( )
112+ const zip = new ZipStream ( )
113113
114114 const content = await this . getTextContent ( uri )
115115
@@ -121,14 +121,14 @@ export class ZipUtil {
121121 // Set includeWorkspaceFolder to false because we are already manually prepending the projectName
122122 const relativePath = vscode . workspace . asRelativePath ( uri , false )
123123 const zipEntryPath = this . getZipEntryPath ( projectName , relativePath )
124- zip . addFile ( zipEntryPath , Buffer . from ( content , 'utf-8' ) )
124+ zip . writeString ( content , zipEntryPath )
125125
126126 if ( scope === CodeWhispererConstants . CodeAnalysisScope . FILE_ON_DEMAND ) {
127127 const gitDiffContent = `+++ b/${ normalize ( zipEntryPath ) } ` // Sending file path in payload for LLM code review
128- zip . addFile ( ZipConstants . codeDiffFilePath , Buffer . from ( gitDiffContent , 'utf-8' ) )
128+ zip . writeString ( gitDiffContent , ZipConstants . codeDiffFilePath )
129129 }
130130 } else {
131- zip . addFile ( uri . fsPath , Buffer . from ( content , 'utf-8' ) )
131+ zip . writeString ( content , uri . fsPath )
132132 }
133133
134134 this . _pickedSourceFiles . add ( uri . fsPath )
@@ -139,7 +139,7 @@ export class ZipUtil {
139139 throw new FileSizeExceededError ( )
140140 }
141141 const zipFilePath = this . getZipDirPath ( FeatureUseCase . CODE_SCAN ) + CodeWhispererConstants . codeScanZipExt
142- zip . writeZip ( zipFilePath )
142+ await zip . finalizeToFile ( zipFilePath )
143143 return zipFilePath
144144 }
145145
@@ -170,13 +170,13 @@ export class ZipUtil {
170170 * await processMetadataDir(zip, '/path/to/directory');
171171 * ```
172172 */
173- protected async processMetadataDir ( zip : admZip , metadataDir : string ) {
173+ protected async processMetadataDir ( zip : ZipStream , metadataDir : string ) {
174174 const metadataDirName = path . basename ( metadataDir )
175175 // Helper function to add empty directory to zip
176176 const addEmptyDirectory = ( dirPath : string ) => {
177177 const relativePath = path . relative ( metadataDir , dirPath )
178178 const pathWithMetadata = path . join ( metadataDirName , relativePath , '/' )
179- zip . addFile ( pathWithMetadata , Buffer . from ( '' ) )
179+ zip . writeString ( '' , pathWithMetadata )
180180 }
181181
182182 // Recursive function to process directories
@@ -193,7 +193,7 @@ export class ZipUtil {
193193 const buffer = Buffer . from ( fileContent )
194194 const relativePath = path . relative ( metadataDir , filePath )
195195 const pathWithMetadata = path . join ( metadataDirName , relativePath )
196- zip . addFile ( pathWithMetadata , buffer )
196+ zip . writeData ( buffer , pathWithMetadata )
197197 } catch ( error ) {
198198 getLogger ( ) . error ( `Failed to add file ${ filePath } to zip: ${ error } ` )
199199 }
@@ -207,7 +207,7 @@ export class ZipUtil {
207207 }
208208
209209 protected async zipProject ( useCase : FeatureUseCase , projectPath ?: string , metadataDir ?: string ) {
210- const zip = new admZip ( )
210+ const zip = new ZipStream ( )
211211 let projectPaths = [ ]
212212 if ( useCase === FeatureUseCase . TEST_GENERATION && projectPath ) {
213213 projectPaths . push ( projectPath )
@@ -232,12 +232,12 @@ export class ZipUtil {
232232 }
233233 this . _language = [ ...languageCount . entries ( ) ] . reduce ( ( a , b ) => ( b [ 1 ] > a [ 1 ] ? b : a ) ) [ 0 ]
234234 const zipFilePath = this . getZipDirPath ( useCase ) + CodeWhispererConstants . codeScanZipExt
235- zip . writeZip ( zipFilePath )
235+ await zip . finalizeToFile ( zipFilePath )
236236 return zipFilePath
237237 }
238238
239239 protected async processCombinedGitDiff (
240- zip : admZip ,
240+ zip : ZipStream ,
241241 projectPaths : string [ ] ,
242242 filePath ?: string ,
243243 scope ?: CodeWhispererConstants . CodeAnalysisScope
@@ -254,7 +254,7 @@ export class ZipUtil {
254254 } )
255255 }
256256 if ( gitDiffContent ) {
257- zip . addFile ( ZipConstants . codeDiffFilePath , Buffer . from ( gitDiffContent , 'utf-8' ) )
257+ zip . writeString ( gitDiffContent , ZipConstants . codeDiffFilePath )
258258 }
259259 }
260260
@@ -403,7 +403,7 @@ export class ZipUtil {
403403 }
404404
405405 protected async processSourceFiles (
406- zip : admZip ,
406+ zip : ZipStream ,
407407 languageCount : Map < CodewhispererLanguage , number > ,
408408 projectPaths : string [ ] | undefined ,
409409 useCase : FeatureUseCase
@@ -444,7 +444,7 @@ export class ZipUtil {
444444 }
445445 }
446446
447- protected processOtherFiles ( zip : admZip , languageCount : Map < CodewhispererLanguage , number > ) {
447+ protected processOtherFiles ( zip : ZipStream , languageCount : Map < CodewhispererLanguage , number > ) {
448448 for ( const document of vscode . workspace . textDocuments
449449 . filter ( ( document ) => document . uri . scheme === 'file' )
450450 . filter ( ( document ) => vscode . workspace . getWorkspaceFolder ( document . uri ) === undefined ) ) {
@@ -474,7 +474,7 @@ export class ZipUtil {
474474 }
475475
476476 protected processTextFile (
477- zip : admZip ,
477+ zip : ZipStream ,
478478 uri : vscode . Uri ,
479479 fileContent : string ,
480480 languageCount : Map < CodewhispererLanguage , number > ,
@@ -493,10 +493,10 @@ export class ZipUtil {
493493 this . _totalLines += fileContent . split ( ZipConstants . newlineRegex ) . length
494494
495495 this . incrementCountForLanguage ( uri , languageCount )
496- zip . addFile ( zipEntryPath , Buffer . from ( fileContent , 'utf-8' ) )
496+ zip . writeString ( fileContent , zipEntryPath )
497497 }
498498
499- protected async processBinaryFile ( zip : admZip , uri : vscode . Uri , zipEntryPath : string ) {
499+ protected async processBinaryFile ( zip : ZipStream , uri : vscode . Uri , zipEntryPath : string ) {
500500 const fileSize = ( await fs . stat ( uri . fsPath ) ) . size
501501
502502 if (
@@ -508,7 +508,7 @@ export class ZipUtil {
508508 this . _pickedSourceFiles . add ( uri . fsPath )
509509 this . _totalSize += fileSize
510510
511- zip . addLocalFile ( uri . fsPath , path . dirname ( zipEntryPath ) )
511+ zip . writeFile ( uri . fsPath , path . dirname ( zipEntryPath ) )
512512 }
513513
514514 protected incrementCountForLanguage ( uri : vscode . Uri , languageCount : Map < CodewhispererLanguage , number > ) {
0 commit comments