libCombine
C++ library for working with the COMBINE Archive format
|
Public Member Functions | |
CombineArchive () | |
Constructs a new COMBINE archive. More... | |
~CombineArchive () | |
Desctructor, also clears all variables by calling cleanUp() More... | |
bool | addFile (const std::string &fileName, const std::string &targetName, const std::string &format, bool isMaster=false) |
Adds a new file to the archive. More... | |
bool | addFile (std::istream &stream, const std::string &targetName, const std::string &format, bool isMaster=false) |
Adds the contents of the stream to the archive. More... | |
bool | addFileFromString (const std::string &content, const std::string &targetName, const std::string &format, bool isMaster=false) |
Adds the given string to the archive. More... | |
int | addMetadata (const std::string &targetName, const OmexDescription &description) |
Adds the given metadata to the list. More... | |
bool | extractEntry (const std::string &name, const std::string &destination=std::string()) |
extracts the content from the entry with the given name More... | |
bool | extractEntryToStream (const std::string &name, std::ostream &stream) |
extracts the entry into the given outptu stream. More... | |
std::string | extractEntryToString (const std::string &name) |
extracts the given entry and returns the contents as string. More... | |
bool | extractTo (const std::string &directory) |
extracts all entries in this archive into the given directory. More... | |
bool | initializeFromDirectory (const std::string &directory) |
initializes this archive with all the content from the given directory More... | |
bool | initializeFromArchive (const std::string &archiveFile, bool skipOmex=false) |
initializes this instance from the given Combine archive More... | |
const CaOmexManifest * | getManifest () const |
CaOmexManifest * | getManifest () |
const CaContent * | getMasterFile () const |
const CaContent * | getMasterFile (const std::string &formatKey) const |
returns the first master file with given format key More... | |
const CaContent * | getEntryByFormat (const std::string &formatKey) const |
returns the first entry with the given format key More... | |
const CaContent * | getEntryByLocation (const std::string &location) const |
returns the first entry with the location More... | |
std::vector< std::string > | getAllLocations () const |
int | getNumEntries () const |
const CaContent * | getEntry (int index) const |
returns the entry at the given index More... | |
OmexDescription | getMetadataForLocation (const std::string &location) const |
returns the metadata for the given location if it does not exist an empty description will be returned. More... | |
bool | hasMetadataForLocation (const std::string &location) const |
returns true, if the the given location does have metadata attached to it. More... | |
void | setManifest (CaOmexManifest *value) |
Sets the manifest to the given value. More... | |
bool | cleanUp () |
cleanUp resets this class (removes tempfiles, clears map and metadata) More... | |
bool | writeToFile (const std::string &fileName) |
writes the archive to the file More... | |
bool | getStream (const std::string &name, std::ifstream &stream) |
returns the stream for the given name More... | |
Protected Member Functions | |
std::string | getNextFilename (const std::string &prefix, const std::string &suffix=".xml") |
returns the next filename that is not yet in the archive with the given prefix and suffix (defaults to .xml) More... | |
int | addMetadataToArchive (OmexDescription &desc, zipper::Zipper *zipper) |
adds the given description to the zip archive (and the manifest). More... | |
Protected Attributes | |
CaOmexManifest * | mpManifest |
the manifest More... | |
std::map< std::string, std::string > | mMap |
a map between the names of the files in this archive and the actual file names on the disc. More... | |
std::map< std::string, OmexDescription > | mMetadataMap |
a map between entries in this archive and metadata descriptions for them. More... | |
zipper::Unzipper * | mpUnzipper |
an unzipper instance, that is used to extract data files. More... | |
std::vector< std::string > | mTempFiles |
a vector of temporary files that have been created in the process of working on the archive. More... | |
CombineArchive::CombineArchive | ( | ) |
Constructs a new COMBINE archive.
CombineArchive::~CombineArchive | ( | ) |
Desctructor, also clears all variables by calling cleanUp()
bool CombineArchive::addFile | ( | const std::string & | fileName, |
const std::string & | targetName, | ||
const std::string & | format, | ||
bool | isMaster = false |
||
) |
Adds a new file to the archive.
fileName | the file to be added |
targetName | the target name of the file in the archive |
format | the format that this file has |
isMaster | boolean indicating whether the file should be opened first if there are multiple ones. |
bool CombineArchive::addFile | ( | std::istream & | stream, |
const std::string & | targetName, | ||
const std::string & | format, | ||
bool | isMaster = false |
||
) |
Adds the contents of the stream to the archive.
stream | input stream with the data. |
targetName | the target name of the file in the archive |
format | the format that this file has |
isMaster | boolean indicating whether the file should be opened first if there are multiple ones. |
bool CombineArchive::addFileFromString | ( | const std::string & | content, |
const std::string & | targetName, | ||
const std::string & | format, | ||
bool | isMaster = false |
||
) |
Adds the given string to the archive.
content | the content of the file to be added to the archive. |
targetName | the target name of the file in the archive |
format | the format that this file has |
isMaster | boolean indicating whether the file should be opened first if there are multiple ones. |
int CombineArchive::addMetadata | ( | const std::string & | targetName, |
const OmexDescription & | description | ||
) |
Adds the given metadata to the list.
targetName | the name of the entry that the metadata is about |
description | the metadata description |
|
protected |
adds the given description to the zip archive (and the manifest).
the entry will be skipped if it is empty.
desc | the description to be added |
zipper | the zipper to be used |
bool CombineArchive::cleanUp | ( | ) |
cleanUp resets this class (removes tempfiles, clears map and metadata)
bool CombineArchive::extractEntry | ( | const std::string & | name, |
const std::string & | destination = std::string() |
||
) |
extracts the content from the entry with the given name
name | the entry to be extracted |
destination | optional filename or folder to save the entry under. If a folder is given, the file will be saved as folder + "/" + name. If the argument is left blank the file will be written into "./" + name. |
bool CombineArchive::extractEntryToStream | ( | const std::string & | name, |
std::ostream & | stream | ||
) |
extracts the entry into the given outptu stream.
name | of the entry to be extracted |
stream | the stream into which to write the contents of the file |
std::string CombineArchive::extractEntryToString | ( | const std::string & | name | ) |
extracts the given entry and returns the contents as string.
name | the entry to be extracted |
bool CombineArchive::extractTo | ( | const std::string & | directory | ) |
extracts all entries in this archive into the given directory.
directory | the directory into which to extract the archive. |
std::vector< std::string > CombineArchive::getAllLocations | ( | ) | const |
const CaContent * CombineArchive::getEntry | ( | int | index | ) | const |
returns the entry at the given index
index | the element to get |
const CaContent * CombineArchive::getEntryByFormat | ( | const std::string & | formatKey | ) | const |
returns the first entry with the given format key
formatKey | the key |
const CaContent * CombineArchive::getEntryByLocation | ( | const std::string & | location | ) | const |
returns the first entry with the location
location | the location |
CaOmexManifest * CombineArchive::getManifest | ( | ) |
const CaOmexManifest * CombineArchive::getManifest | ( | ) | const |
const CaContent * CombineArchive::getMasterFile | ( | ) | const |
const CaContent * CombineArchive::getMasterFile | ( | const std::string & | formatKey | ) | const |
returns the first master file with given format key
formatKey | the format key |
OmexDescription CombineArchive::getMetadataForLocation | ( | const std::string & | location | ) | const |
returns the metadata for the given location if it does not exist an empty description will be returned.
location | the location |
|
protected |
returns the next filename that is not yet in the archive with the given prefix and suffix (defaults to .xml)
prefix | the prefix for the file |
suffix | the suffix |
int CombineArchive::getNumEntries | ( | ) | const |
bool CombineArchive::getStream | ( | const std::string & | name, |
std::ifstream & | stream | ||
) |
returns the stream for the given name
name | the name that should be in the current map of files |
stream | the stream for the found entry |
bool CombineArchive::hasMetadataForLocation | ( | const std::string & | location | ) | const |
returns true, if the the given location does have metadata attached to it.
location | the location |
bool CombineArchive::initializeFromArchive | ( | const std::string & | archiveFile, |
bool | skipOmex = false |
||
) |
initializes this instance from the given Combine archive
archiveFile | the combine archive file |
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. |
bool CombineArchive::initializeFromDirectory | ( | const std::string & | directory | ) |
initializes this archive with all the content from the given directory
directory | the directory, from which all files will be added recursively to this archive. (excluding a file called "manifest.xml"). |
void CombineArchive::setManifest | ( | CaOmexManifest * | value | ) |
Sets the manifest to the given value.
value | the manifest |
bool CombineArchive::writeToFile | ( | const std::string & | fileName | ) |
writes the archive to the file
fileName | the filename |
|
protected |
a map between the names of the files in this archive and the actual file names on the disc.
In case a combine archive was opened, this filename will be prefixed with "unzipper://" to indicate that the file is to be read from the unzipper pointer.
|
protected |
a map between entries in this archive and metadata descriptions for them.
|
protected |
the manifest
|
protected |
an unzipper instance, that is used to extract data files.
|
protected |
a vector of temporary files that have been created in the process of working on the archive.
They will be deleted automatically upon destruction of the instance.