SlHelpers
Toggle main menu visibility
Loading...
Searching...
No Matches
Curl.h
1
// SPDX-License-Identifier: GPL-2.0-only
2
3
#pragma once
4
5
#include <chrono>
6
#include <filesystem>
7
#include <optional>
8
#include <ostream>
9
#include <string>
10
11
typedef
void
CURL;
12
13
namespace
SlCurl {
14
18
class
LibCurl
{
19
public
:
25
LibCurl
();
26
~LibCurl
();
27
35
bool
downloadToStream
(
const
std::string &url,
const
std::ostream &stream,
36
unsigned
*HTTPErrorCode =
nullptr
);
37
45
bool
downloadToFile
(
const
std::string &url,
const
std::filesystem::path &file,
46
unsigned
*HTTPErrorCode =
nullptr
);
47
48
55
std::optional<std::string>
download
(
const
std::string &url,
56
unsigned
*HTTPErrorCode =
nullptr
);
57
64
static
std::optional<std::string>
singleDownload
(
const
std::string &url,
65
unsigned
*HTTPErrorCode =
nullptr
);
66
74
static
bool
singleDownloadToFile
(
const
std::string &url,
75
const
std::filesystem::path &file,
76
unsigned
*HTTPErrorCode =
nullptr
);
77
86
static
bool
isDownloadNeeded
(
const
std::filesystem::path &filePath,
bool
&fileAlreadyExists,
87
bool
forceRefresh,
const
std::chrono::hours &hours);
88
98
static
std::filesystem::path
fetchFileIfNeeded
(
const
std::filesystem::path &filePath,
99
const
std::string &url,
100
bool
forceRefresh,
bool
ignoreErrors,
101
const
std::chrono::hours &hours);
102
104
static
const
std::string &
lastError
() {
return
m_lastError; }
105
private
:
106
CURL *handle;
107
static
thread_local
std::string m_lastError;
108
};
109
110
}
SlCurl::LibCurl::singleDownload
static std::optional< std::string > singleDownload(const std::string &url, unsigned *HTTPErrorCode=nullptr)
Download url to a string (and create LibCurl temporarily).
SlCurl::LibCurl::lastError
static const std::string & lastError()
Return the last error string if some.
Definition
Curl.h:104
SlCurl::LibCurl::LibCurl
LibCurl()
Construct LibCurl.
SlCurl::LibCurl::fetchFileIfNeeded
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.
SlCurl::LibCurl::downloadToFile
bool downloadToFile(const std::string &url, const std::filesystem::path &file, unsigned *HTTPErrorCode=nullptr)
Download url to file.
SlCurl::LibCurl::download
std::optional< std::string > download(const std::string &url, unsigned *HTTPErrorCode=nullptr)
Download url to a string.
SlCurl::LibCurl::isDownloadNeeded
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.
SlCurl::LibCurl::downloadToStream
bool downloadToStream(const std::string &url, const std::ostream &stream, unsigned *HTTPErrorCode=nullptr)
Download url to stream.
SlCurl::LibCurl::singleDownloadToFile
static bool singleDownloadToFile(const std::string &url, const std::filesystem::path &file, unsigned *HTTPErrorCode=nullptr)
Download url to file (and create LibCurl temporarily).
include
curl
Curl.h
Generated by
1.17.0