[nim-dev] Re: A problem about the httpclient module

  • From: karatin <karantin3030@xxxxxxx>
  • To: nim-dev@xxxxxxxxxxxxx
  • Date: Sat, 28 May 2016 16:23:36 +0000

Your code

```nim
proc download(fullpath:cstring,url:cstring) {.exportc: "download".} =
  var path:string
  path = splitPath($fullpath)[0]
  if not existsDir(path):
    echo "No such dir, but i had made it!"
    createDir(path)
 
  downloadFile2($url, $fullpath,
    userAgent="Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; 
en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 
Safari/6533.18.5",
    )
```

means that you export c function and declare new 
`download(fullpath:cstring,url:cstring)` function.
You could just export that function:

```nim
proc download(fullpath:cstring,url:cstring) {.exportc: "download".}
```

or declare it without exporting

```nim
proc download(fullpath:cstring,url:cstring) =
  var path:string
  path = splitPath($fullpath)[0]
  if not existsDir(path):
    echo "No such dir, but i had made it!"
    createDir(path)
 
  downloadFile2($url, $fullpath,
    userAgent="Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; 
en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 
Safari/6533.18.5",
    )
```

Other related posts: