Skip to content

Commit

Permalink
#61 : allow initialization from an unzipper instance
Browse files Browse the repository at this point in the history
Using the unzipper instance directly, callers can either initialize that one from file or from memory buffers, and just pass that one along.
  • Loading branch information
fbergmann committed Jun 22, 2023
1 parent 94b6156 commit 952db94
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/combine/combinearchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,15 @@ CombineArchive::initializeFromDirectory(const std::string &directory)
return true;
}

bool
bool
CombineArchive::initializeFromArchive(
const std::string &archiveFile,
bool skipOmex /*= false*/)
zipper::Unzipper* pUnzipper,
bool skipOmex/*=false*/)
{
cleanUp();

try
{
mpUnzipper = new Unzipper(archiveFile);
}
catch (const std::exception&)
{
// invalid COMBINE archive, it should always have a manifest
cleanUp();
return false;
}
if (mpUnzipper != NULL && mpUnzipper != pUnzipper)
delete mpUnzipper;

mpUnzipper = pUnzipper;

// now build the map of all files in the archive
std::vector<zipper::ZipEntry> entries = mpUnzipper->entries();
Expand Down Expand Up @@ -147,6 +139,28 @@ CombineArchive::initializeFromArchive(
return true;
}


bool
CombineArchive::initializeFromArchive(
const std::string &archiveFile,
bool skipOmex /*= false*/)
{
cleanUp();

try
{
mpUnzipper = new Unzipper(archiveFile);
}
catch (const std::exception&)
{
// invalid COMBINE archive, it should always have a manifest
cleanUp();
return false;
}

return initializeFromArchive(mpUnzipper, skipOmex);
}

bool CombineArchive::cleanUp()
{
mMap.clear();
Expand Down
17 changes: 17 additions & 0 deletions src/combine/combinearchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,23 @@ class LIBCOMBINE_EXTERN CombineArchive
bool initializeFromArchive(const std::string& archiveFile,
bool skipOmex=false);

/**
* initializes this instance from an unzipper instance of a
* combine archive
*
* @param unzipper the unzipper instance
* @param skipOmex optional flag indicating whether meta data processing
* should be skipped or not (default). The metadata processing, removes
* annotations in the restricted 2014 subset of the OMEX Metadata and
* adds them to the convenience classes.
*
* @return boolean indicating success or failure
*/
bool initializeFromArchive(zipper::Unzipper* pUnzipper,
bool skipOmex=false);



/**
* @return the manifest
*/
Expand Down

0 comments on commit 952db94

Please sign in to comment.