Downloading a file and showing progress via curl.

Daniel Kozak kozzi11 at gmail.com
Tue Aug 20 11:46:50 UTC 2019


On Tue, Aug 20, 2019 at 1:40 PM BoQsc via Digitalmars-d-learn
<digitalmars-d-learn at puremagic.com> wrote:
>
> Hello everyone,
> I found this snippet on
> https://dlang.org/phobos/std_net_curl.html#.HTTP
>
> > import std.net.curl : HTTP;
> > import std.stdio : writeln;
> >
> > void main()
> > {
> >     auto http = HTTP();
> >     // Track progress
> >     http.method = HTTP.Method.get;
> >     http.url =
> > "https://upload.wikimedia.org/wikipedia/commons/5/53/Wikipedia-logo-en-big.png";
> >     http.onReceive = (ubyte[] data) { return data.length; };
> >     http.onProgress = (size_t dltotal, size_t dlnow, size_t
> > ultotal, size_t ulnow) {
> >         writeln("Progress ", dltotal, ", ", dlnow, ", ",
> > ultotal, ", ", ulnow);
> >         return 0;
> >     };
> >     http.perform();
> > }
>
> This snippet is showing Download Progress in bytes, but I'm
> unsure how to save the
> downloaded file into filesystem after download is completed.

You just need to save data in onReceive callback


More information about the Digitalmars-d-learn mailing list