INNER CODE UNIT · TypeScript

calculateProgress

SurgeDM/Surge · extension/entrypoints/popup/store/index.ts:160

function calculateProgress(downloaded: number, totalSize: number): number {
  return totalSize > 0 ? (downloaded / totalSize) * 100 : 0;
}

export function handleSseEvent(event: string, data: unknown): void {
  switch (event) {
    case 'progress': {
      const message = data as ProgressMsg;
      updateActiveDownload(message.DownloadID, (download) => {
        const totalSize = message.Total || download.total_size;
        return {
          ...download,
          downloaded: message.Downloaded,
          progress: calculateProgress(message.Downloaded, totalSize),
          speed: message.Speed / MB,
          eta: message.Speed > 0 ? Math.ceil((totalSize - message.Downloaded) / message.Speed) : 0,
          connections: message.ActiveConnections,
          total_size: totalSize,

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…