nimgrab tool: use Windows API for the download if possible
This commit is contained in:
parent
0ccbc82344
commit
82bf1e6697
2 changed files with 454 additions and 9 deletions
|
|
@ -1,15 +1,29 @@
|
|||
|
||||
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), "%"
|
||||
when defined(windows):
|
||||
import os, urldownloader
|
||||
|
||||
client.onProgressChanged = onProgressChanged
|
||||
client.downloadFile(url, file)
|
||||
echo "100%"
|
||||
proc syncDownload(url, file: string) =
|
||||
proc progress(status: DownloadStatus, progress: uint, total: uint,
|
||||
message: string) {.procvar, gcsafe.} =
|
||||
echo "Downloading " & url
|
||||
echo clamp(int(progress.BiggestInt*100 div total.BiggestInt), 0, 100), "%"
|
||||
|
||||
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%"
|
||||
|
||||
if os.paramCount() != 2:
|
||||
quit "Usage: nimgrab <url> <file>"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue