From 41a402f0529102e7744f2ec1095fa033f9f73a7f Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 15 May 2024 16:07:59 -0400 Subject: [PATCH 1/4] Change the way the file is downloaded to speed it up --- src/Public/Get-RemoteChecksum.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Public/Get-RemoteChecksum.ps1 b/src/Public/Get-RemoteChecksum.ps1 index 0b735ab..bebd0fe 100644 --- a/src/Public/Get-RemoteChecksum.ps1 +++ b/src/Public/Get-RemoteChecksum.ps1 @@ -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() From 826e3501d6f39e62aa9fb28ab66dff62bf76327b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 15 May 2024 16:07:59 -0400 Subject: [PATCH 2/4] (#58) Speed up Get-RemoteChecksum 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. --- src/Public/Get-RemoteChecksum.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Public/Get-RemoteChecksum.ps1 b/src/Public/Get-RemoteChecksum.ps1 index 0b735ab..bebd0fe 100644 --- a/src/Public/Get-RemoteChecksum.ps1 +++ b/src/Public/Get-RemoteChecksum.ps1 @@ -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() From cfe6bde53ba0ed45d23085c695b473bd4b25e683 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 22 May 2024 10:57:51 -0400 Subject: [PATCH 3/4] (chocolatey-community#58) Speed up Get-RemoteChecksum 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. Added modified date in this commit --- src/Public/Get-RemoteChecksum.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Public/Get-RemoteChecksum.ps1 b/src/Public/Get-RemoteChecksum.ps1 index bebd0fe..f1fbde1 100644 --- a/src/Public/Get-RemoteChecksum.ps1 +++ b/src/Public/Get-RemoteChecksum.ps1 @@ -1,5 +1,5 @@ # Author: Miodrag Milic -# Last Change: 26-Nov-2016. +# Last Change: 22-May-2024. <# .SYNOPSIS From bbd1bfe94bc445af21a3fd1a1695acd5bc1bc161 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 3 Jun 2024 17:27:50 -0400 Subject: [PATCH 4/4] (#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