Always use httpclient in nimgrab (#19767)

This commit is contained in:
Yardanico 2022-05-17 10:56:39 +03:00 • committed by GitHub
commit 06f02bb771
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 459 deletions

View file

@ -1,33 +1,14 @@
import std/[os, httpclient]
proc syncDownload(url, file: string) =
var client = newHttpClient()
proc onProgressChanged(total, progress, speed: BiggestInt) =
echo "Downloading " & url & " " & $(speed div 1000) & "kb/s"
echo clamp(int(progress*100 div total), 0, 100), "%"
when defined(windows):
import os, urldownloader
proc syncDownload(url, file: string) =
proc progress(status: DownloadStatus, progress: uint, total: uint,
message: string) {.gcsafe.} =
echo "Downloading " & url
let t = total.BiggestInt
if t != 0:
echo clamp(int(progress.BiggestInt*100 div t), 0, 100), "%"
else:
echo "0%"
downloadToFile(url, file, {optUseCache}, progress)
echo "100%"
else:
import os, asyncdispatch, httpclient
proc syncDownload(url, file: string) =
var client = newHttpClient()
proc onProgressChanged(total, progress, speed: BiggestInt) =
echo "Downloading " & url & " " & $(speed div 1000) & "kb/s"
echo clamp(int(progress*100 div total), 0, 100), "%"
client.onProgressChanged = onProgressChanged
client.downloadFile(url, file)
echo "100%"
client.onProgressChanged = onProgressChanged
client.downloadFile(url, file)
echo "100%"
if os.paramCount() != 2:
quit "Usage: nimgrab <url> <file>"