1
0
Fork 0
phantsure/download-progress
Sampark Sharma 2023-02-10 11:52:49 +00:00 committed by GitHub
parent 3d0da1ea1a
commit ae026cf7c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View File

@ -10,7 +10,7 @@ import * as util from 'util'
import * as utils from './cacheUtils'
import {SocketTimeout} from './constants'
import {DownloadOptions} from '../options'
import {retryHttpClientResponse} from './requestUtils'
import {retryHttpClientResponse, sleep} from './requestUtils'
import {AbortController} from '@azure/abort-controller'
@ -162,22 +162,23 @@ export class DownloadProgress {
}
async function displayDownloadProgress(socket: any, startTime: number): Promise<void> {
while(!socket.complete) {
const transferredBytes = socket.bytesRead
while(!socket.destroyed) {
const byteRead = socket.bytesRead
const totalBytes = 100000
const percentage = (100 * (transferredBytes / totalBytes)).toFixed(
const percentage = (100 * (byteRead / totalBytes)).toFixed(
1
)
const elapsedTime = Date.now() - startTime
const downloadSpeed = (
transferredBytes /
byteRead /
(1024 * 1024) /
(elapsedTime / 1000)
).toFixed(1)
core.info(
`Received ${transferredBytes} of ${totalBytes} (${percentage}%), ${downloadSpeed} MBs/sec`
`Received ${byteRead} of ${totalBytes} (${percentage}%), ${downloadSpeed} MBs/sec`
)
sleep(10)
}
}

View File

@ -33,7 +33,7 @@ export function isRetryableStatusCode(statusCode?: number): boolean {
return retryableStatusCodes.includes(statusCode)
}
async function sleep(milliseconds: number): Promise<void> {
export async function sleep(milliseconds: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}