I've implemented the read half of the std::streambuf
API (i.e., underflow()
and xsgetn()
) around libcurl so that an ordinary istream
can have such a streambuf
plugged into it and retrieve the contents from HTTP or FTP servers. It works great.
Now I'd like to implement the write half of the API (i.e., overflow()
and xsputn()
) for uploading files to an FTP server to do something like:
ostream os( my_curl_streambuf );
curl_easy_setopt( my_curl_handle, CURLOPT_UPLOAD, 1L );
os << is->rdbuf(); // copy entire contents of istream "is" to ostream "os"
The problem is that libcurl uses a "pull" API via a read-callback function set via CURLOPT_READFUNCTION
whereas the last code line above is a "push" way of doing it.
Can this be made to work? I.e., wrap libcurl with the streambuf
API for both reading and writing?