Wrapper class for libcurl.
More...
#include <Curl.h>
|
| | LibCurl () |
| | Construct LibCurl. More...
|
| |
| bool | downloadToStream (const std::string &url, const std::ostream &stream, unsigned *HTTPErrorCode=nullptr) |
| | Download url to stream. More...
|
| |
| bool | downloadToFile (const std::string &url, const std::filesystem::path &file, unsigned *HTTPErrorCode=nullptr) |
| | Download url to file. More...
|
| |
| std::optional< std::string > | download (const std::string &url, unsigned *HTTPErrorCode=nullptr) |
| | Download url to a string. More...
|
| |
|
| static std::optional< std::string > | singleDownload (const std::string &url, unsigned *HTTPErrorCode=nullptr) |
| | Download url to a string (and create LibCurl temporarily) More...
|
| |
| static bool | singleDownloadToFile (const std::string &url, const std::filesystem::path &file, unsigned *HTTPErrorCode=nullptr) |
| | Download url to file (and create LibCurl temporarily) More...
|
| |
| static bool | isDownloadNeeded (const std::filesystem::path &filePath, bool &fileAlreadyExists, bool forceRefresh, const std::chrono::hours &hours) |
| | Check if filePath is old enough that it should be downloaded. More...
|
| |
| static std::filesystem::path | fetchFileIfNeeded (const std::filesystem::path &filePath, const std::string &url, bool forceRefresh, bool ignoreErrors, const std::chrono::hours &hours) |
| | Fetch url and store into filePath. More...
|
| |
|
static const std::string & | lastError () |
| | Return the last error string if some.
|
| |
Wrapper class for libcurl.
◆ LibCurl()
| SlCurl::LibCurl::LibCurl |
( |
| ) |
|
Construct LibCurl.
Either make a LibCurl and use non-static methods; or use the static methods.
◆ download()
| std::optional<std::string> SlCurl::LibCurl::download |
( |
const std::string & |
url, |
|
|
unsigned * |
HTTPErrorCode = nullptr |
|
) |
| |
Download url to a string.
- Parameters
-
| url | URL to download |
| HTTPErrorCode | HTTP error code returned from the server (or nullptr) |
- Returns
- Downloaded content or nullopt on failure.
◆ downloadToFile()
| bool SlCurl::LibCurl::downloadToFile |
( |
const std::string & |
url, |
|
|
const std::filesystem::path & |
file, |
|
|
unsigned * |
HTTPErrorCode = nullptr |
|
) |
| |
Download url to file.
- Parameters
-
| url | URL to download |
| file | Where to store the downloaded content to |
| HTTPErrorCode | HTTP error code returned from the server (or nullptr) |
- Returns
- true for success.
◆ downloadToStream()
| bool SlCurl::LibCurl::downloadToStream |
( |
const std::string & |
url, |
|
|
const std::ostream & |
stream, |
|
|
unsigned * |
HTTPErrorCode = nullptr |
|
) |
| |
Download url to stream.
- Parameters
-
| url | URL to download |
| stream | Stream to store to |
| HTTPErrorCode | HTTP error code returned from the server (or nullptr) |
- Returns
- true for success.
◆ fetchFileIfNeeded()
| static std::filesystem::path SlCurl::LibCurl::fetchFileIfNeeded |
( |
const std::filesystem::path & |
filePath, |
|
|
const std::string & |
url, |
|
|
bool |
forceRefresh, |
|
|
bool |
ignoreErrors, |
|
|
const std::chrono::hours & |
hours |
|
) |
| |
|
static |
Fetch url and store into filePath.
- Parameters
-
| filePath | File to store to |
| url | The URL to fetch |
| forceRefresh | Fetch in any case (ignore hours) |
| ignoreErrors | Errors are ignored |
| hours | After how many hours this file expires (and is downloaded again) |
- Returns
- Path to the fetched file or nullopt in case of error.
◆ isDownloadNeeded()
| static bool SlCurl::LibCurl::isDownloadNeeded |
( |
const std::filesystem::path & |
filePath, |
|
|
bool & |
fileAlreadyExists, |
|
|
bool |
forceRefresh, |
|
|
const std::chrono::hours & |
hours |
|
) |
| |
|
static |
Check if filePath is old enough that it should be downloaded.
- Parameters
-
| filePath | The file to check |
| fileAlreadyExists | Stored true if the file exists already |
| forceRefresh | Download in any case. |
| hours | After how many hours this file expires (and is downloaded again) |
- Returns
- True if a download should be performed.
◆ singleDownload()
| static std::optional<std::string> SlCurl::LibCurl::singleDownload |
( |
const std::string & |
url, |
|
|
unsigned * |
HTTPErrorCode = nullptr |
|
) |
| |
|
static |
Download url to a string (and create LibCurl temporarily)
- Parameters
-
| url | URL to download |
| HTTPErrorCode | HTTP error code returned from the server (or nullptr) |
- Returns
- Downloaded content or nullopt on failure.
◆ singleDownloadToFile()
| static bool SlCurl::LibCurl::singleDownloadToFile |
( |
const std::string & |
url, |
|
|
const std::filesystem::path & |
file, |
|
|
unsigned * |
HTTPErrorCode = nullptr |
|
) |
| |
|
static |
Download url to file (and create LibCurl temporarily)
- Parameters
-
| url | URL to download |
| file | Where to store the downloaded content to |
| HTTPErrorCode | HTTP error code returned from the server (or nullptr) |
- Returns
- true for success.
The documentation for this class was generated from the following file:
- /home/abuild/rpmbuild/BUILD/slhelpers-20260428.f233ce9/include/curl/Curl.h