nexuslua
Loading...
Searching...
No Matches
utility.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2025 acrion innovations GmbH
3Authors: Stefan Zipproth, s.zipproth@acrion.ch
4
5This file is part of nexuslua, see https://github.com/acrion/nexuslua and https://nexuslua.org
6
7nexuslua is offered under a commercial and under the AGPL license.
8For commercial licensing, contact us at https://acrion.ch/sales. For AGPL licensing, see below.
9
10AGPL licensing:
11
12nexuslua is free software: you can redistribute it and/or modify
13it under the terms of the GNU Affero General Public License as published by
14the Free Software Foundation, either version 3 of the License, or
15(at your option) any later version.
16
17nexuslua is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU Affero General Public License for more details.
21
22You should have received a copy of the GNU Affero General Public License
23along with nexuslua. If not, see <https://www.gnu.org/licenses/>.
24*/
25
26#pragma once
27
28#include "nexuslua_export.h"
29
30#include <filesystem>
31#include <functional>
32#include <string>
33
34namespace nexuslua
35{
47
49 namespace utility
50 {
57 NEXUSLUA_EXPORT std::string ReadHttp(const std::string& URL, const std::string& outFile = "", std::function<void(DownloadProgress, std::string)> progress = nullptr, std::function<bool()> abort = nullptr);
58
67 NEXUSLUA_EXPORT std::string ReadHttp(const std::string& host, const std::string& port, const std::string& path, const std::string& outFile = "", std::function<void(DownloadProgress, std::string)> progress = nullptr, std::function<bool()> abort = nullptr);
68
77 NEXUSLUA_EXPORT std::string ReadHttps(const std::string& host, const std::string& port, const std::string& path, const std::string& outFile = "", std::function<void(DownloadProgress, std::string)> progress = nullptr, std::function<bool()> abort = nullptr);
78
79 NEXUSLUA_EXPORT std::string RemoveWsFromParams(std::string signature);
80 NEXUSLUA_EXPORT void ParseHostPortPath(std::string URL, std::string& host, std::string& port, std::string& path);
81 NEXUSLUA_EXPORT bool Unzip(std::filesystem::path zip_file, std::filesystem::path target_dir);
82 NEXUSLUA_EXPORT bool Zip(std::filesystem::path source_dir, std::filesystem::path zip_file);
83 }
84}
various helper functions
Definition utility.hpp:50
NEXUSLUA_EXPORT void ParseHostPortPath(std::string URL, std::string &host, std::string &port, std::string &path)
splits up the given URL into the three components host, port and path and sets the reference paramete...
NEXUSLUA_EXPORT std::string RemoveWsFromParams(std::string signature)
removes redundant white spaces from the given function signature
NEXUSLUA_EXPORT std::string ReadHttps(const std::string &host, const std::string &port, const std::string &path, const std::string &outFile="", std::function< void(DownloadProgress, std::string)> progress=nullptr, std::function< bool()> abort=nullptr)
reads a file from a the given URL
NEXUSLUA_EXPORT std::string ReadHttp(const std::string &URL, const std::string &outFile="", std::function< void(DownloadProgress, std::string)> progress=nullptr, std::function< bool()> abort=nullptr)
reads a file from a the given URL (no https)
NEXUSLUA_EXPORT bool Zip(std::filesystem::path source_dir, std::filesystem::path zip_file)
zips the given target directory to the given output zip file. Throws std::runtime_error in case of er...
NEXUSLUA_EXPORT bool Unzip(std::filesystem::path zip_file, std::filesystem::path target_dir)
unzips the given zip file to the given target dir. Throws std::runtime_error in case of errors.
The nexuslua library is implemented inside this namespace.
DownloadProgress
used by utils::ReadHttp to call a function to describe the download state, including a string with fu...
Definition utility.hpp:38
@ READING_HTTP_RESPONSE
Definition utility.hpp:41
@ DOWNLOADING
string will contain current download size
Definition utility.hpp:43
@ ABORTED
Definition utility.hpp:45
@ READING_DATA
Definition utility.hpp:42
@ CONNECTING
Definition utility.hpp:39
@ ERR
string will contain error message
Definition utility.hpp:44
@ SENDING_REQUEST
Definition utility.hpp:40