nimgrab.nim 621 B

123456789101112131415161718192021222324
  1. import std/[os, httpclient]
  2. proc syncDownload(url, file: string) =
  3. let client = newHttpClient()
  4. proc onProgressChanged(total, progress, speed: BiggestInt) =
  5. var message = "Downloading "
  6. message.add url
  7. message.add ' '
  8. message.addInt speed div 1000
  9. message.add "kb/s\n"
  10. message.add $clamp(int(progress * 100 div total), 0, 100)
  11. message.add '%'
  12. echo message
  13. client.onProgressChanged = onProgressChanged
  14. client.downloadFile(url, file)
  15. client.close()
  16. echo "100%"
  17. if os.paramCount() != 2:
  18. quit "Usage: nimgrab <url> <file>"
  19. else:
  20. syncDownload(os.paramStr(1), os.paramStr(2))