stil / CurlThin

Lightweight cURL wrapper for C# with support for curl_multi polling interface through libuv
Other
68 stars 18 forks source link

Curl command line #14

Open greenbergjosh opened 4 years ago

greenbergjosh commented 4 years ago

I apologize if this is not the correct place for this question, but I did not find a better alternative.

I would like to use curl from a C# application. I see I can use CurlThin, which is great, but I was wondering if there might be a different interface that I am missing.

It would be amazing to be able to something like var x = await curlthin.cmd("curl -O ftp://speedtest.tele2.net/1MB.zip");

It would be even more amazing to be able to get back the stream instead of having the result always written to a file var stream = await curlthin.cmd("curl -O ftp://speedtest.tele2.net/1MB.zip", getBackStream=true);

I am actually asking for a few different things, and then really asking if something like this is possible without rewriting a lot of code.

  1. With the calls above, all of the normal curl command line options/syntax is retained. I can literally just use a curl command without modification. Of course, I can just kick off a cmd/terminal or a process and get this behavior as well, but I have to leave C# a bit more to do that - which brings up the next point.
  2. In my calls above, I was intending that a new process was not kicked off for each call I make to curl. Instead, a thread, but really a Task is created - so async I/O, and no processes. I cannot do this by kicking off a cmd/terminal window or creating a new process.
  3. In my second call, I am giving the stream back directly to the C# application instead of always writing the result to a file. However, I don't have to dig for the stream or use an API to get it - it's just returned. Truly, even if it weren't returned, if I could just pass in a callback function, that would work great too.

The whole key to what I am suggesting/asking is whether there is a way to leverage the command line syntax of curl without having to recreate all of it. Then, if that is possible, is there a way to do so that is async and can provide easy access to the resultant stream. That would really be like curl is in my C# application as opposed to libcurl. The value of the curl command line cannot be overstated. It is a widely used an accepted syntax. To be able to drop it directly into a function call would be huge. To be able to have that function either write to a file, or to yield back a stream, would make integration a snap. That way, when I want to grab a file from an ftp and write it to my local filesystem, it's simple. And, when I want to make an HTTP POST and get back the response stream, it's equally simple. Plus, I don't have to rewrite the command line parser that curl has already written and perfected.

Thank you for any advice or thoughts on whether this can be done or how I might approach it. It would be fantastic if I just missed this in the API docs for curlthin or if there is some other project that works along with curlthin to support this.

Kind Regards

greenbergjosh commented 4 years ago

I would like to see something like the above created and placed into open source. I am willing to fund that effort if anyone would like to work on the project either as a full time member of my team or as a contractor. Please reply here if there is any interest.