Skip to content

Commit

Permalink
update percentage for 0 byte files
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Mar 27, 2024
1 parent a4a0db0 commit f8b89cb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/compiler/file_uploader/upload_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export async function uploadFile(
);

await throttle();
const percentComplete = ((startIndex + bytesRead) / fileSize) * 100;
const percentComplete = calculatePercentComplete(
startIndex + bytesRead,
fileSize
);
console.info(
`Uploading chunk: ${srcPath} | ${bytesToHumanReadable(
startIndex + bytesRead
Expand Down Expand Up @@ -57,3 +60,12 @@ async function throttle() {
await new Promise((resolve) => setTimeout(resolve, 500)); // Should be 500 (ie 1 every 1/2 second or 2 every second)
}
}
function calculatePercentComplete(
bytesComplete: number,
fileSize: number
): number {
if (bytesComplete === 0 && fileSize === 0) {
return 100;
}
return (bytesComplete / Math.max(fileSize, 1)) * 100;
}

0 comments on commit f8b89cb

Please sign in to comment.