SlHelpers
Loading...
Searching...
No Matches
SlCurl::LibCurl Class Reference

Wrapper class for libcurl. More...

#include <Curl.h>

Public Member Functions

 LibCurl ()
 Construct LibCurl.
bool downloadToStream (const std::string &url, const std::ostream &stream, unsigned *HTTPErrorCode=nullptr)
 Download url to stream.
bool downloadToFile (const std::string &url, const std::filesystem::path &file, unsigned *HTTPErrorCode=nullptr)
 Download url to file.
std::optional< std::string > download (const std::string &url, unsigned *HTTPErrorCode=nullptr)
 Download url to a string.

Static Public Member Functions

static std::optional< std::string > singleDownload (const std::string &url, unsigned *HTTPErrorCode=nullptr)
 Download url to a string (and create LibCurl temporarily).
static bool singleDownloadToFile (const std::string &url, const std::filesystem::path &file, unsigned *HTTPErrorCode=nullptr)
 Download url to file (and create LibCurl temporarily).
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.
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.
static const std::string & lastError ()
 Return the last error string if some.

Detailed Description

Wrapper class for libcurl.

Constructor & Destructor Documentation

◆ LibCurl()

SlCurl::LibCurl::LibCurl ( )

Construct LibCurl.

Either make a LibCurl and use non-static methods; or use the static methods.

Member Function Documentation

◆ download()

std::optional< std::string > SlCurl::LibCurl::download ( const std::string & url,
unsigned * HTTPErrorCode = nullptr )

Download url to a string.

Parameters
urlURL to download
HTTPErrorCodeHTTP 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
urlURL to download
fileWhere to store the downloaded content to
HTTPErrorCodeHTTP 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
urlURL to download
streamStream to store to
HTTPErrorCodeHTTP error code returned from the server (or nullptr)
Returns
true for success.

◆ fetchFileIfNeeded()

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
filePathFile to store to
urlThe URL to fetch
forceRefreshFetch in any case (ignore hours)
ignoreErrorsErrors are ignored
hoursAfter how many hours this file expires (and is downloaded again)
Returns
Path to the fetched file or nullopt in case of error.

◆ isDownloadNeeded()

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
filePathThe file to check
fileAlreadyExistsStored true if the file exists already
forceRefreshDownload in any case.
hoursAfter how many hours this file expires (and is downloaded again)
Returns
True if a download should be performed.

◆ singleDownload()

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
urlURL to download
HTTPErrorCodeHTTP error code returned from the server (or nullptr)
Returns
Downloaded content or nullopt on failure.

◆ singleDownloadToFile()

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
urlURL to download
fileWhere to store the downloaded content to
HTTPErrorCodeHTTP 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-build/slhelpers-20260428.f233ce9/include/curl/Curl.h