Skip to content

Commit

Permalink
(chocolatey-community#58) Speed up Get-RemoteChecksum
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chrrobi committed Jun 3, 2024
1 parent cfe6bde commit bbd1bfe
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/Public/Get-RemoteChecksum.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Author: Miodrag Milic <[email protected]>
# Last Change: 22-May-2024.
# Last Change: 3-June-2024.

<#
.SYNOPSIS
Expand All @@ -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()
}

}

0 comments on commit bbd1bfe

Please sign in to comment.