Skip to content

Commit cecd581

Browse files
author
Tatyana Kostromskaya
authored
Resolve comments
1 parent f51ed70 commit cecd581

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

tool.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,12 @@ export async function downloadTool(
241241
throw err;
242242
}
243243

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+
}
245250

246251
tl.debug('creating stream');
247252
let file: NodeJS.WritableStream = fs.createWriteStream(destPath);
@@ -275,17 +280,26 @@ export async function downloadTool(
275280
});
276281
}
277282

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+
//---------------------
285286

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);
286295
return parsedContentLength;
287296
}
288297

298+
/**
299+
* Gets size of file saved to disk
300+
*
301+
* @param filePath the path to the file, saved to the disk
302+
*/
289303
function _getFileSizeOnDisk(filePath: string): number {
290304
try {
291305
let fileStats = fs.statSync(filePath);
@@ -295,6 +309,7 @@ function _getFileSizeOnDisk(filePath: string): number {
295309
}
296310
catch (err) {
297311
tl.debug(`Unable to find file size for ${filePath}`);
312+
tl.warning(`Unable to find file size for ${filePath} due to error: ${err.Message}`);
298313
return NaN;
299314
}
300315
}

0 commit comments

Comments
 (0)