nimgrab.nim 495 B

1234567891011121314151617
  1. import std/[os, httpclient]
  2. proc syncDownload(url, file: string) =
  3. var client = newHttpClient()
  4. proc onProgressChanged(total, progress, speed: BiggestInt) =
  5. echo "Downloading " & url & " " & $(speed div 1000) & "kb/s"
  6. echo clamp(int(progress*100 div total), 0, 100), "%"
  7. client.onProgressChanged = onProgressChanged
  8. client.downloadFile(url, file)
  9. echo "100%"
  10. if os.paramCount() != 2:
  11. quit "Usage: nimgrab <url> <file>"
  12. else:
  13. syncDownload(os.paramStr(1), os.paramStr(2))