reksar / vsget

Portable MS Visual C++, MS Build, Windows SDK
17 stars 0 forks source link

Invoke-WebRequest in download.bat - very slow (solution inside) #1

Closed anacondaq closed 1 year ago

anacondaq commented 1 year ago

Original file:

@echo off

rem  --------------------------------------------------------------------------
rem  Downloads content from [URL] to [OUTFILE] (must be an abs path).
rem
rem  Using:
rem
rem    download [URL] [OUTFILE]
rem
rem  --------------------------------------------------------------------------

setlocal

set url=%~1
set outfile=%~2

call powershell -command ^
  "Invoke-WebRequest -UseBasicParsing -Uri '%url%' -OutFile '%outfile%'"

endlocal

modify to:

@echo off

rem  --------------------------------------------------------------------------
rem  Downloads content from [URL] to [OUTFILE] (must be an abs path).
rem
rem  Using:
rem
rem    download [URL] [OUTFILE]
rem
rem  --------------------------------------------------------------------------

setlocal

set url=%~1
set outfile=%~2

call powershell -command ^
  "Set-Variable ProgressPreference SilentlyContinue ; Invoke-WebRequest -UseBasicParsing -Uri '%url%' -OutFile '%outfile%'"

endlocal

Problem with very slow Invoke-WebRequest explained here: https://stackoverflow.com/questions/28682642/powershell-why-is-using-invoke-webrequest-much-slower-than-a-browser-download

Or https://github.com/PowerShell/PowerShell/issues/2138

i.e. in powershells 5.1 (default for windows 10) This command because of progress bar 50x-100x times slower than other alternatives or without the bar (on fast connections).

Why is it a problem? Because of Win10 sdk download.

reksar commented 1 year ago

Thanks for the improvement!

I changed the download.bat to prefer using curl or JScript, but using PowerShell is still a reserve method.