From b5bfa6808a4707d7479d5fc0d4aed0344e52a40c Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Tue, 4 Jun 2024 13:07:34 +1200 Subject: [PATCH] Added addFileFromBuffer(). --- src/combine/combinearchive.cpp | 18 ++++++++++++++++++ src/combine/combinearchive.h | 17 +++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/combine/combinearchive.cpp b/src/combine/combinearchive.cpp index b2f3808..81a2dce 100644 --- a/src/combine/combinearchive.cpp +++ b/src/combine/combinearchive.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -536,6 +537,23 @@ CombineArchive::addFile(std::istream &stream, return addFile(tempFilename, targetName, format, isMaster); } +bool +CombineArchive::addFileFromBuffer(const std::vector &buffer, + const std::string &targetName, + const std::string &format, + bool isMaster) +{ + std::string tempFilename = Util::getTempFilename(); + mTempFiles.push_back(tempFilename); + + std::ofstream out(tempFilename.c_str(), std::ios::out | std::ios::binary); + + std::copy(buffer.begin(), buffer.end(), + std::ostream_iterator(out)); + + return addFile(tempFilename, targetName, format, isMaster); +} + int CombineArchive::addMetadata(const std::string &targetName, const OmexDescription &description) diff --git a/src/combine/combinearchive.h b/src/combine/combinearchive.h index dbfee93..d5d23a1 100644 --- a/src/combine/combinearchive.h +++ b/src/combine/combinearchive.h @@ -118,6 +118,23 @@ class LIBCOMBINE_EXTERN CombineArchive const std::string& targetName, const std::string& format, bool isMaster = false); + + /** + * Adds the given buffer to the archive. + * + * @param buffer the buffer of the file to be added to the archive. + * @param targetName the target name of the file in the archive + * @param format the format that this file has + * @param isMaster boolean indicating whether the file should be + * opened first if there are multiple ones. + * + * @return boolean indicating success or failure + */ + bool addFileFromBuffer(const std::vector& buffer, + const std::string& targetName, + const std::string& format, + bool isMaster = false); + /** * Adds the given metadata to the list. *