Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2021
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.74 KB | None | 0 0
  1. import libcurl
  2.  
  3. proc curlWriteFn(
  4.     buffer: cstring,
  5.     size: int,
  6.     count: int,
  7.     outstream: pointer): int =
  8.    
  9.     let outbuf = cast[ref string](outstream)
  10.     outbuf[] &= cast[string](buffer)[0..count]
  11.     result = size*count
  12.  
  13. let webData: ref string = new string
  14. let curl = easy_init()
  15.  
  16. discard curl.easy_setopt(OPT_USERAGENT,"Mozilla/5.0")
  17. discard curl.easy_setopt(OPT_FOLLOWLOCATION,true)
  18. discard curl.easy_setopt(OPT_MAXREDIRS,5)
  19. discard curl.easy_setopt(OPT_WRITEDATA,webData)
  20. discard curl.easy_setopt(OPT_WRITEFUNCTION,curlWriteFn)
  21. discard curl.easy_setopt(OPT_url,"path/to/zipfile.zip")
  22.  
  23. let ret = curl.easy_perform()
  24. if ret==E_OK:
  25.     echo "download completed"
  26. let wf = open("zipfile.zip", fmWrite)
  27. wf.write(webData[])
  28. wfile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement