Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import libcurl
- proc curlWriteFn(
- buffer: cstring,
- size: int,
- count: int,
- outstream: pointer): int =
- let outbuf = cast[ref string](outstream)
- outbuf[] &= cast[string](buffer)[0..count]
- result = size*count
- let webData: ref string = new string
- let curl = easy_init()
- discard curl.easy_setopt(OPT_USERAGENT,"Mozilla/5.0")
- discard curl.easy_setopt(OPT_FOLLOWLOCATION,true)
- discard curl.easy_setopt(OPT_MAXREDIRS,5)
- discard curl.easy_setopt(OPT_WRITEDATA,webData)
- discard curl.easy_setopt(OPT_WRITEFUNCTION,curlWriteFn)
- discard curl.easy_setopt(OPT_url,"path/to/zipfile.zip")
- let ret = curl.easy_perform()
- if ret==E_OK:
- echo "download completed"
- let wf = open("zipfile.zip", fmWrite)
- wf.write(webData[])
- wfile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement