Skip to content

Commit

Permalink
Added addFileFromBuffer().
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Jun 4, 2024
1 parent 01d319b commit b5bfa68
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/combine/combinearchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <zipper/unzipper.h>

#include <fstream>
#include <iterator>
#include <sstream>
#include <cstdio>

Expand Down Expand Up @@ -536,6 +537,23 @@ CombineArchive::addFile(std::istream &stream,
return addFile(tempFilename, targetName, format, isMaster);
}

bool
CombineArchive::addFileFromBuffer(const std::vector<unsigned char> &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<unsigned char>(out));

return addFile(tempFilename, targetName, format, isMaster);
}

int
CombineArchive::addMetadata(const std::string &targetName,
const OmexDescription &description)
Expand Down
17 changes: 17 additions & 0 deletions src/combine/combinearchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char>& buffer,
const std::string& targetName,
const std::string& format,
bool isMaster = false);

/**
* Adds the given metadata to the list.
*
Expand Down

0 comments on commit b5bfa68

Please sign in to comment.