Skip to content

Commit

Permalink
Added extractEntryToMemory().
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Jun 4, 2024
1 parent 2fd6d7b commit 01d319b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
37 changes: 33 additions & 4 deletions src/combine/combinearchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,8 @@ bool CombineArchive::writeToFile(const std::string &fileName)
return true;
}

bool
CombineArchive::getStream(const std::string &name,
std::ifstream &stream)
std::map<std::string, std::string>::iterator
CombineArchive::mapIterator(const std::string &name)
{
std::map<std::string, std::string>::iterator it = mMap.find(name);
if (it == mMap.end())
Expand All @@ -324,9 +323,19 @@ CombineArchive::getStream(const std::string &name,
if (name.find("/") == 0)
it = mMap.find(name.substr(1));
if (it == mMap.end())
return false;
return mMap.end();
}
}
return it;
}

bool
CombineArchive::getStream(const std::string &name,
std::ifstream &stream)
{
auto it = mapIterator(name);
if (it == mMap.end())
return false;

std::string filename = (*it).second;
if (filename.find("unzipper://") == 0)
Expand Down Expand Up @@ -576,3 +585,23 @@ CombineArchive::extractEntryToString(const std::string& name)
extractEntryToStream(name, stream);
return stream.str();
}

std::vector<unsigned char>
CombineArchive::extractEntryToBuffer(const std::string& name)
{
auto it = mapIterator(name);
if (it == mMap.end())
return {};

std::string filename = (*it).second;
if (filename.find("unzipper://") == 0)
filename = filename.substr(std::string("unzipper://").length());

if (mpUnzipper == NULL)
return {};

std::vector<unsigned char> res;
mpUnzipper->extractEntryToMemory(filename, res);

return res;
}
18 changes: 18 additions & 0 deletions src/combine/combinearchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ class LIBCOMBINE_EXTERN CombineArchive
*/
std::string extractEntryToString(const std::string& name);

/**
* extracts the given entry and returns the contents as a buffer.
*
* @param name the entry to be extracted
*
* @return the content of the entry, or empty if not found.
*/
std::vector<unsigned char> extractEntryToBuffer(const std::string& name);

/**
* extracts all entries in this archive into the given directory.
*
Expand Down Expand Up @@ -402,6 +411,15 @@ class LIBCOMBINE_EXTERN CombineArchive
*
*/
int addMetadataToArchive(OmexDescription& desc, zipper::Zipper* zipper);

/**
* returns the map iterator for the given file.
*
* @param name the name that should be in the current map of files
*
* @return the map iterator
*/
std::map<std::string, std::string>::iterator mapIterator(const std::string &name);
};

LIBCOMBINE_CPP_NAMESPACE_END
Expand Down

0 comments on commit 01d319b

Please sign in to comment.