2022-03-14 23:31:30 +01:00
|
|
|
#pragma once
|
|
|
|
#include "api/http_request.hpp"
|
|
|
|
|
|
|
|
namespace big::remote
|
|
|
|
{
|
|
|
|
inline bool download_binary(const std::string_view file_url, const std::filesystem::path& location)
|
|
|
|
{
|
|
|
|
std::ofstream file(location, std::ios::binary | std::ios::trunc);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
http::Request req(file_url.data());
|
2022-03-16 13:23:51 +01:00
|
|
|
http::Response res = req.send("GET", "", {}, 10s);
|
2022-03-14 23:31:30 +01:00
|
|
|
|
|
|
|
std::ostream_iterator<std::uint8_t> outputIter(file);
|
|
|
|
std::copy(res.body.begin(), res.body.end(), outputIter);
|
|
|
|
}
|
|
|
|
catch (const std::exception& e)
|
|
|
|
{
|
|
|
|
LOG(INFO) << "Failed to download binary, is the host down?: " << e.what();
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|