Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Invoke-WebRequest with .NET webclient to speed up downloads in Get-RemoteChecksum function #59

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 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: 26-Nov-2016.
# Last Change: 3-June-2024.

<#
.SYNOPSIS
Expand All @@ -8,9 +8,19 @@
#>
function Get-RemoteChecksum( [string] $Url, $Algorithm='sha256', $Headers ) {
$fn = [System.IO.Path]::GetTempFileName()
Invoke-WebRequest $Url -OutFile $fn -UseBasicParsing -Headers $Headers
$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()
}

}