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 1 commit
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
Prev Previous commit
(#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.
chrrobi committed Jun 3, 2024
commit bbd1bfe94bc445af21a3fd1a1695acd5bc1bc161
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
@@ -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()
}

}