From bbd1bfe94bc445af21a3fd1a1695acd5bc1bc161 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 3 Jun 2024 17:27:50 -0400 Subject: [PATCH] (#58) Speed up Get-RemoteChecksum The current Get_RemoteChecksum implementation uses Invoke-WebRequest with progress bar which can be slow on larger files. This results in a long checksumming process during automated packaging. By providing the option to hide the progress bar, while losing the "interactive" download update, we significantly increase the speed of the download. --- src/Public/Get-RemoteChecksum.ps1 | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Public/Get-RemoteChecksum.ps1 b/src/Public/Get-RemoteChecksum.ps1 index f1fbde1..852422d 100644 --- a/src/Public/Get-RemoteChecksum.ps1 +++ b/src/Public/Get-RemoteChecksum.ps1 @@ -1,5 +1,5 @@ # Author: Miodrag Milic -# Last Change: 22-May-2024. +# Last Change: 3-June-2024. <# .SYNOPSIS @@ -8,10 +8,19 @@ #> function Get-RemoteChecksum( [string] $Url, $Algorithm='sha256', $Headers ) { $fn = [System.IO.Path]::GetTempFileName() - $wc = New-Object net.webclient - $wc.DownloadFile($Url, $fn) - $res = Get-FileHash $fn -Algorithm $Algorithm | ForEach-Object Hash + + $originalShowProgress=$ProgressPreference + if (-not $showProgress) + { + $ProgressPreference = 'SilentlyContinue' + } + Invoke-WebRequest $Url -OutFile $fn -UseBasicParsing -Headers $Headers + if (-not $showProgress) + { + $ProgressPreference = $originalShowProgress + } + + $res = Get-FileHash $fn -Algorithm $Algorithm | ForEach-Object Hash Remove-Item $fn -ea ignore return $res.ToLower() -} - +} \ No newline at end of file