1
0
Fork 0

Add download progress for httpclient method

phantsure/download-progress
Sampark Sharma 2023-02-10 11:34:10 +00:00 committed by GitHub
parent 409d616a6e
commit 3d0da1ea1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 0 deletions

View File

@ -161,6 +161,26 @@ export class DownloadProgress {
}
}
async function displayDownloadProgress(socket: any, startTime: number): Promise<void> {
while(!socket.complete) {
const transferredBytes = socket.bytesRead
const totalBytes = 100000
const percentage = (100 * (transferredBytes / totalBytes)).toFixed(
1
)
const elapsedTime = Date.now() - startTime
const downloadSpeed = (
transferredBytes /
(1024 * 1024) /
(elapsedTime / 1000)
).toFixed(1)
core.info(
`Received ${transferredBytes} of ${totalBytes} (${percentage}%), ${downloadSpeed} MBs/sec`
)
}
}
/**
* Download the cache using the Actions toolkit http-client
*
@ -171,6 +191,7 @@ export async function downloadCacheHttpClient(
archiveLocation: string,
archivePath: string
): Promise<void> {
const startTime = Date.now()
const writeStream = fs.createWriteStream(archivePath)
const httpClient = new HttpClient('actions/cache')
const downloadResponse = await retryHttpClientResponse(
@ -184,6 +205,8 @@ export async function downloadCacheHttpClient(
core.debug(`Aborting download, socket timed out after ${SocketTimeout} ms`)
})
await displayDownloadProgress(downloadResponse.message.socket, startTime)
await pipeResponseToStream(downloadResponse, writeStream)
// Validate download size.