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
which can be slow on larger files. This results in a long checksumming
process during automated packaging. By switching to the .NET webclient,
while losing the "interactive" download update, we significantly increase
the speed of the download. For example, on a 150 mb file, it went from minutes
to download to seconds.
  • Loading branch information
chrrobi committed May 22, 2024
1 parent b1180bc commit 826e350
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Public/Get-RemoteChecksum.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#>
function Get-RemoteChecksum( [string] $Url, $Algorithm='sha256', $Headers ) {
$fn = [System.IO.Path]::GetTempFileName()
Invoke-WebRequest $Url -OutFile $fn -UseBasicParsing -Headers $Headers
$wc = New-Object net.webclient
$wc.DownloadFile($Url, $fn)
$res = Get-FileHash $fn -Algorithm $Algorithm | ForEach-Object Hash
Remove-Item $fn -ea ignore
return $res.ToLower()
Expand Down

0 comments on commit 826e350

Please sign in to comment.