@@ -30,6 +30,7 @@ export interface ZipMetadata {
30
30
export const ZipConstants = {
31
31
newlineRegex : / \r ? \n / ,
32
32
gitignoreFilename : '.gitignore' ,
33
+ knownBinaryFileExts : [ '.class' ] ,
33
34
}
34
35
35
36
export class ZipUtil {
@@ -149,10 +150,15 @@ export class ZipUtil {
149
150
this . getProjectScanPayloadSizeLimitInBytes ( )
150
151
)
151
152
for ( const file of sourceFiles ) {
152
- const isFileOpenAndDirty = this . isFileOpenAndDirty ( file . fileUri )
153
- const fileContent = isFileOpenAndDirty ? await this . getTextContent ( file . fileUri ) : file . fileContent
154
153
const zipEntryPath = this . getZipEntryPath ( file . workspaceFolder . name , file . zipFilePath )
155
- this . processFile ( zip , file . fileUri , fileContent , languageCount , zipEntryPath )
154
+
155
+ if ( ZipConstants . knownBinaryFileExts . includes ( path . extname ( file . fileUri . fsPath ) ) ) {
156
+ await this . processBinaryFile ( zip , file . fileUri , zipEntryPath )
157
+ } else {
158
+ const isFileOpenAndDirty = this . isFileOpenAndDirty ( file . fileUri )
159
+ const fileContent = isFileOpenAndDirty ? await this . getTextContent ( file . fileUri ) : file . fileContent
160
+ this . processTextFile ( zip , file . fileUri , fileContent , languageCount , zipEntryPath )
161
+ }
156
162
}
157
163
}
158
164
@@ -161,11 +167,11 @@ export class ZipUtil {
161
167
. filter ( ( document ) => document . uri . scheme === 'file' )
162
168
. filter ( ( document ) => vscode . workspace . getWorkspaceFolder ( document . uri ) === undefined )
163
169
. forEach ( ( document ) =>
164
- this . processFile ( zip , document . uri , document . getText ( ) , languageCount , document . uri . fsPath )
170
+ this . processTextFile ( zip , document . uri , document . getText ( ) , languageCount , document . uri . fsPath )
165
171
)
166
172
}
167
173
168
- protected processFile (
174
+ protected processTextFile (
169
175
zip : admZip ,
170
176
uri : vscode . Uri ,
171
177
fileContent : string ,
@@ -188,6 +194,21 @@ export class ZipUtil {
188
194
zip . addFile ( zipEntryPath , Buffer . from ( fileContent , 'utf-8' ) )
189
195
}
190
196
197
+ protected async processBinaryFile ( zip : admZip , uri : vscode . Uri , zipEntryPath : string ) {
198
+ const fileSize = ( await fs . stat ( uri . fsPath ) ) . size
199
+
200
+ if (
201
+ this . reachSizeLimit ( this . _totalSize , CodeWhispererConstants . CodeAnalysisScope . PROJECT ) ||
202
+ this . willReachSizeLimit ( this . _totalSize , fileSize )
203
+ ) {
204
+ throw new ProjectSizeExceededError ( )
205
+ }
206
+ this . _pickedSourceFiles . add ( uri . fsPath )
207
+ this . _totalSize += fileSize
208
+
209
+ zip . addLocalFile ( uri . fsPath , path . dirname ( zipEntryPath ) )
210
+ }
211
+
191
212
protected incrementCountForLanguage ( uri : vscode . Uri , languageCount : Map < CodewhispererLanguage , number > ) {
192
213
const fileExtension = path . extname ( uri . fsPath ) . slice ( 1 )
193
214
const language = runtimeLanguageContext . getLanguageFromFileExtension ( fileExtension )
0 commit comments