Downloading a file and showing progress via curl.

BoQsc vaidas.boqsc at gmail.com
Tue Aug 20 12:22:07 UTC 2019


On Tuesday, 20 August 2019 at 11:51:03 UTC, Daniel Kozak wrote:
> For that you can use https://dlang.org/phobos/std_file#append

Thank you, seems to work.

> import std.net.curl : HTTP;
> import std.stdio    : writeln;
> import std.file     : append;
> 
> 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) {
>         append("Wikipedia-logo-en-big.png", 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();
> }


More information about the Digitalmars-d-learn mailing list