@@ -241,7 +241,12 @@ export async function downloadTool(
241
241
throw err ;
242
242
}
243
243
244
- let downloadedContentLength = _getContentLengthOfDownloadedFile ( response . message . headers [ 'content-length' ] ) ;
244
+ let downloadedContentLength = _getContentLengthOfDownloadedFile ( response ) ;
245
+ if ( ! isNaN ( downloadedContentLength ) ) {
246
+ tl . debug ( `Content-Length of downloaded file: ${ downloadedContentLength } ` ) ;
247
+ } else {
248
+ tl . debug ( `Content-Length header missing.` ) ;
249
+ }
245
250
246
251
tl . debug ( 'creating stream' ) ;
247
252
let file : NodeJS . WritableStream = fs . createWriteStream ( destPath ) ;
@@ -275,17 +280,26 @@ export async function downloadTool(
275
280
} ) ;
276
281
}
277
282
278
- function _getContentLengthOfDownloadedFile ( contentLengthHeader : string | undefined ) : number {
279
- let parsedContentLength = parseInt ( contentLengthHeader ) ;
280
- if ( ! isNaN ( parsedContentLength ) ) {
281
- tl . debug ( `Content-Length of downloaded file: ${ parsedContentLength } ` ) ;
282
- } else {
283
- tl . debug ( `Content-Length header missing.` ) ;
284
- }
283
+ //---------------------
284
+ // Size functions
285
+ //---------------------
285
286
287
+ /**
288
+ * Gets size of downloaded file from "Content-Length" header
289
+ *
290
+ * @param response response for request to get the file
291
+ */
292
+ function _getContentLengthOfDownloadedFile ( response : httpm . HttpClientResponse ) : number {
293
+ let contentLengthHeader = response . message . headers [ 'content-length' ]
294
+ let parsedContentLength = parseInt ( contentLengthHeader ) ;
286
295
return parsedContentLength ;
287
296
}
288
297
298
+ /**
299
+ * Gets size of file saved to disk
300
+ *
301
+ * @param filePath the path to the file, saved to the disk
302
+ */
289
303
function _getFileSizeOnDisk ( filePath : string ) : number {
290
304
try {
291
305
let fileStats = fs . statSync ( filePath ) ;
@@ -295,6 +309,7 @@ function _getFileSizeOnDisk(filePath: string): number {
295
309
}
296
310
catch ( err ) {
297
311
tl . debug ( `Unable to find file size for ${ filePath } ` ) ;
312
+ tl . warning ( `Unable to find file size for ${ filePath } due to error: ${ err . Message } ` ) ;
298
313
return NaN ;
299
314
}
300
315
}
0 commit comments