mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-12 22:39:09 -05:00
Add new Lua function to save base64-encoded files to disk
This commit is contained in:
+1
-1
Submodule ext/ghoul updated: ef8f8f8278...4219692f42
@@ -1727,6 +1727,7 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() {
|
||||
codegen::lua::RemoveTag,
|
||||
codegen::lua::DownloadFile,
|
||||
codegen::lua::CreateSingleColorImage,
|
||||
codegen::lua::SaveBase64File,
|
||||
codegen::lua::IsMaster,
|
||||
codegen::lua::Version,
|
||||
codegen::lua::ReadCSVFile,
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/io/texture/texturewriter.h>
|
||||
#include <ghoul/lua/lua_helper.h>
|
||||
#include <ghoul/misc/base64.h>
|
||||
#include <ghoul/misc/csvreader.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
@@ -198,6 +199,23 @@ namespace {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function takes a base64 encoded data string, decodes it and saves the resulting
|
||||
* data to the provided filepath.
|
||||
*
|
||||
* \param filePath The location where the data will be saved. Any file that already exists
|
||||
* in that location will be overwritten
|
||||
* \param base64Data The base64 encoded data that should be saved to the provided file
|
||||
*/
|
||||
[[codegen::luawrap]] void saveBase64File(std::filesystem::path filepath,
|
||||
std::string base64Data)
|
||||
{
|
||||
std::vector<uint8_t> data = ghoul::decodeBase64(base64Data);
|
||||
|
||||
std::ofstream file = std::ofstream(filepath, std::ofstream::binary);
|
||||
file.write(reinterpret_cast<char*>(data.data()), data.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the current OpenSpace instance is the master node of a cluster
|
||||
* configuration. If this instance is not part of a cluster, this function also returns
|
||||
|
||||
Reference in New Issue
Block a user