mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 08:54:53 +00:00
Fix Nimgrab (#21918)
* . * Fix nimgrab client not closing * Fix nimgrab client not closing * Fix nimgrab client not closing
This commit is contained in:
@@ -1,13 +1,20 @@
|
||||
import std/[os, httpclient]
|
||||
|
||||
proc syncDownload(url, file: string) =
|
||||
var client = newHttpClient()
|
||||
let 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), "%"
|
||||
var message = "Downloading "
|
||||
message.add url
|
||||
message.add ' '
|
||||
message.addInt speed div 1000
|
||||
message.add "kb/s\n"
|
||||
message.add $clamp(int(progress * 100 div total), 0, 100)
|
||||
message.add '%'
|
||||
echo message
|
||||
|
||||
client.onProgressChanged = onProgressChanged
|
||||
client.downloadFile(url, file)
|
||||
client.close()
|
||||
echo "100%"
|
||||
|
||||
if os.paramCount() != 2:
|
||||
|
||||
Reference in New Issue
Block a user