digitalmars.D.learn - how to use curl to download a file
- =?iso-8859-1?b?RnLpZOlyaWM=?= Galusik <fredg salixosnospam.org> Nov 01 2011
- Mike Parker <aldacron gmail.com> Nov 01 2011
- Ary Manzana <ary esperanto.org.ar> Nov 02 2011
- bearophile <bearophileHUGS lycos.com> Nov 02 2011
- "Nick Sabalausky" <a a.a> Nov 02 2011
- Jonas Drewsen <jdrewsen nospam.com> Nov 02 2011
- Mike Parker <aldacron gmail.com> Nov 03 2011
- Jesse Phillips <jessekphillips+d gmail.com> Nov 02 2011
- Graham Fawcett <fawcett uwindsor.ca> Nov 02 2011
- Graham Fawcett <fawcett uwindsor.ca> Nov 02 2011
- =?iso-8859-1?b?RnLpZOlyaWM=?= Galusik <fredg salixosnospam.org> Nov 02 2011
- Graham Fawcett <fawcett uwindsor.ca> Nov 02 2011
Hi, As the curl documentation is a little bit ...wow. http://www.digitalmars.com/d/2.0/phobos/etc_c_curl.html Do someone have a simple example on how to download a simple file ? Thank you. ++
Nov 01 2011
On 11/2/2011 3:20 AM, Frédéric Galusik wrote:Hi, As the curl documentation is a little bit ...wow. http://www.digitalmars.com/d/2.0/phobos/etc_c_curl.html Do someone have a simple example on how to download a simple file ? Thank you. ++
I don't think we should expect detailed documentation for modules in etc.c. These are interfaces to existing C libraries, not Phobos-specific modules. There's no need to duplicate existing documentation. If you want to learn how to use libcurl, the place to look is the libcurl homepage. http://curl.haxx.se/libcurl/
Nov 01 2011
On 11/1/11 11:49 PM, Mike Parker wrote:On 11/2/2011 3:20 AM, Frédéric Galusik wrote:Hi, As the curl documentation is a little bit ...wow. http://www.digitalmars.com/d/2.0/phobos/etc_c_curl.html Do someone have a simple example on how to download a simple file ? Thank you. ++
I don't think we should expect detailed documentation for modules in etc.c. These are interfaces to existing C libraries, not Phobos-specific modules. There's no need to duplicate existing documentation. If you want to learn how to use libcurl, the place to look is the libcurl homepage. http://curl.haxx.se/libcurl/
Wrong. If you want programmers to use D, give them the solution, now. It's not that hard to put a little example at the top of the page showing a basic usage.
Nov 02 2011
Ary Manzana:Wrong. If you want programmers to use D, give them the solution, now. It's not that hard to put a little example at the top of the page showing a basic usage.
That wall of links at the top of the page is useless. I don't want to use that C API. This is how you download a file in Python (urllib2 is fully inside the Python standard library) and save it in a local file: import urllib2 data = urllib2.urlopen("http://server.com/file.html").read() open('file.html', 'w').write(data) I think in Clojure or Rebol (http://en.wikipedia.org/wiki/REBOL ) languages it's even simpler. Bye, bearophile
Nov 02 2011
"Jesse Phillips" <jessekphillips+d gmail.com> wrote in message news:j8rj3c$uc2$1 digitalmars.com...etc.c.curl is meant for those that know curl and wish to use it. etc.curl has been delayed but is intended for those that wish to access the internet.
In the meantime, the proposed etc.curl is at least available somewhere to grab and use, isn't it?
Nov 02 2011
Den 02-11-2011 17:17, Frédéric Galusik skrev:Le Wed, 02 Nov 2011 15:23:36 +0000, Graham Fawcett a écrit :On Wed, 02 Nov 2011 11:10:17 -0400, Nick Sabalausky wrote:"Jesse Phillips"<jessekphillips+d gmail.com> wrote in message news:j8rj3c$uc2$1 digitalmars.com...etc.c.curl is meant for those that know curl and wish to use it. etc.curl has been delayed but is intended for those that wish to access the internet.
to grab and use, isn't it?
Good point. Probably better to grab that than my binding (which I suggested in another post). https://github.com/jcd/phobos/blob/curl-wrapper/etc/curl.d docs: http://freeze.steamwinter.com/D/web/phobos/etc_curl.html reference: http://www.mail-archive.com/digitalmars-d puremagic.com/ msg63605.html Best, Graham
Yes, etc.curl is well documented and is really more understandable Thank you for this wrapper. Is there a chance that it will become std.curl one day ?
Andrei asked me to rename it to std.curl so I believe it will yes. Still working on it but not at max speed since I'm quite busy at work currently. /Jonas
Nov 02 2011
On 11/2/2011 9:43 PM, Ary Manzana wrote:On 11/1/11 11:49 PM, Mike Parker wrote:On 11/2/2011 3:20 AM, Frédéric Galusik wrote:Hi, As the curl documentation is a little bit ...wow. http://www.digitalmars.com/d/2.0/phobos/etc_c_curl.html Do someone have a simple example on how to download a simple file ? Thank you. ++
I don't think we should expect detailed documentation for modules in etc.c. These are interfaces to existing C libraries, not Phobos-specific modules. There's no need to duplicate existing documentation. If you want to learn how to use libcurl, the place to look is the libcurl homepage. http://curl.haxx.se/libcurl/
Wrong. If you want programmers to use D, give them the solution, now.
It's a D binding to a C library. The interface is the same.It's not that hard to put a little example at the top of the page showing a basic usage.
Wrappers over these libraries should be documented, sure. But for the C interface, IMO, a link to the project homepage is sufficient. Any differences on the D side should be mentioned, of course. But that's all. Otherwise, how many examples should be given? Which functionality should be shown? libcurl, specifically, has several examples already available from the project page. Adding more to the D docs is redundant.
Nov 03 2011
etc.c.curl is meant for those that know curl and wish to use it. etc.curl has been delayed but is intended for those that wish to access the internet.
Nov 02 2011
On Wed, 02 Nov 2011 11:10:17 -0400, Nick Sabalausky wrote:"Jesse Phillips" <jessekphillips+d gmail.com> wrote in message news:j8rj3c$uc2$1 digitalmars.com...etc.c.curl is meant for those that know curl and wish to use it. etc.curl has been delayed but is intended for those that wish to access the internet.
to grab and use, isn't it?
Good point. Probably better to grab that than my binding (which I suggested in another post). https://github.com/jcd/phobos/blob/curl-wrapper/etc/curl.d docs: http://freeze.steamwinter.com/D/web/phobos/etc_curl.html reference: http://www.mail-archive.com/digitalmars-d puremagic.com/ msg63605.html Best, Graham
Nov 02 2011
On Wed, 02 Nov 2011 15:23:36 +0000, Graham Fawcett wrote:On Wed, 02 Nov 2011 11:10:17 -0400, Nick Sabalausky wrote:"Jesse Phillips" <jessekphillips+d gmail.com> wrote in message news:j8rj3c$uc2$1 digitalmars.com...etc.c.curl is meant for those that know curl and wish to use it. etc.curl has been delayed but is intended for those that wish to access the internet.
to grab and use, isn't it?
Good point. Probably better to grab that than my binding (which I suggested in another post). https://github.com/jcd/phobos/blob/curl-wrapper/etc/curl.d docs: http://freeze.steamwinter.com/D/web/phobos/etc_curl.html
Hm, that 'docs' link is broken, but the github link is still good. Grahamreference: http://www.mail-archive.com/digitalmars-d puremagic.com/ msg63605.html Best, Graham
Nov 02 2011
Le Wed, 02 Nov 2011 15:23:36 +0000, Graham Fawcett a écrit :On Wed, 02 Nov 2011 11:10:17 -0400, Nick Sabalausky wrote:"Jesse Phillips" <jessekphillips+d gmail.com> wrote in message news:j8rj3c$uc2$1 digitalmars.com...etc.c.curl is meant for those that know curl and wish to use it. etc.curl has been delayed but is intended for those that wish to access the internet.
to grab and use, isn't it?
Good point. Probably better to grab that than my binding (which I suggested in another post). https://github.com/jcd/phobos/blob/curl-wrapper/etc/curl.d docs: http://freeze.steamwinter.com/D/web/phobos/etc_curl.html reference: http://www.mail-archive.com/digitalmars-d puremagic.com/ msg63605.html Best, Graham
Yes, etc.curl is well documented and is really more understandable Thank you for this wrapper. Is there a chance that it will become std.curl one day ? Regards. ++
Nov 02 2011
On Tue, 01 Nov 2011 18:20:25 +0000, Frédéric Galusik wrote:Hi, As the curl documentation is a little bit ...wow. http://www.digitalmars.com/d/2.0/phobos/etc_c_curl.html Do someone have a simple example on how to download a simple file ? Thank you.
Until the high-level bindings for curl are available in Phobos, I have a little module you could use. https://github.com/gmfawcett/d-play-libcurl/blob/master/fawcett/curl.d The default version prints the result to stdout, and there's a commented main() that shows how to get a callback when data is received. If you wanted to download directly into a file, you could do this: import std.stdio; import fawcett.curl; class FileCurl : Curl { this(string url, File f) { handle = curl_easy_init(); set(CURLoption.URL, url); set(CURLoption.FILE, cast(void*) f.getFP); } } void main() { auto f = File("/tmp/stuff", "w"); auto c = new FileCurl("http://example.com/", f); c.perform(); } Note, it doesn't call super() in the constructor, which is bad form, but the current default constructor is overkill for just downloading a file. (It's not a production-quality curl binding.) Rather than putting my module in 'fawcett/curl.d', you might just want to remove the 'module' line in 'curl.d' and put it in the same directory as your program. Best, Graham
Nov 02 2011
Le Wed, 02 Nov 2011 15:09:17 +0000, Graham Fawcett a écrit :On Tue, 01 Nov 2011 18:20:25 +0000, Frédéric Galusik wrote:Hi, As the curl documentation is a little bit ...wow. http://www.digitalmars.com/d/2.0/phobos/etc_c_curl.html Do someone have a simple example on how to download a simple file ? Thank you.
Until the high-level bindings for curl are available in Phobos, I have a little module you could use. https://github.com/gmfawcett/d-play-libcurl/blob/master/fawcett/curl.d The default version prints the result to stdout, and there's a commented main() that shows how to get a callback when data is received. If you wanted to download directly into a file, you could do this: import std.stdio; import fawcett.curl; class FileCurl : Curl { this(string url, File f) { handle = curl_easy_init(); set(CURLoption.URL, url); set(CURLoption.FILE, cast(void*) f.getFP); } } void main() { auto f = File("/tmp/stuff", "w"); auto c = new FileCurl("http://example.com/", f); c.perform(); } Note, it doesn't call super() in the constructor, which is bad form, but the current default constructor is overkill for just downloading a file. (It's not a production-quality curl binding.) Rather than putting my module in 'fawcett/curl.d', you might just want to remove the 'module' line in 'curl.d' and put it in the same directory as your program. Best, Graham
Thank you very much, it's very interesting. Best regards. ++ fredg
Nov 02 2011









Jonas Drewsen <jdrewsen nospam.com> 