diff options
author | Yardanico <tiberiumk12@gmail.com> | 2022-05-17 10:56:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-17 09:56:39 +0200 |
commit | 06f02bb7716066241b04b2a92a3a61f539eadff2 (patch) | |
tree | 2477912b7998fd86cdd15b9980dd6ad6f688d925 /tools/nimgrab.nim | |
parent | 33888a73840a7f9fa46f79e613d488de2d193916 (diff) | |
download | Nim-06f02bb7716066241b04b2a92a3a61f539eadff2.tar.gz |
Always use httpclient in nimgrab (#19767)
Diffstat (limited to 'tools/nimgrab.nim')
-rw-r--r-- | tools/nimgrab.nim | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/tools/nimgrab.nim b/tools/nimgrab.nim index ee5eced1e..7e4161faf 100644 --- a/tools/nimgrab.nim +++ b/tools/nimgrab.nim @@ -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>" |