|
coral
A C++ library for distributed co-simulation
|
A class for reading ZIP archives. More...
#include "coral/util/zip.hpp"
Public Member Functions | |
| Archive () CORAL_NOEXCEPT | |
| Default constructor; does not associate the object with an archive file. | |
| Archive (const boost::filesystem::path &path) | |
| Constructor which opens a ZIP archive. More... | |
| Archive (Archive &&) CORAL_NOEXCEPT | |
| Move constructor. | |
| Archive & | operator= (Archive &&) CORAL_NOEXCEPT |
| Move assignment operator. | |
| ~Archive () CORAL_NOEXCEPT | |
| Destructor; calls Discard(). | |
| void | Open (const boost::filesystem::path &path) |
| Opens a ZIP archive. More... | |
| void | Discard () CORAL_NOEXCEPT |
| Closes the archive. More... | |
| bool | IsOpen () const CORAL_NOEXCEPT |
| Returns whether this object refers to an open ZIP archive. | |
| std::uint64_t | EntryCount () const |
| Returns the number of entries in the archive. More... | |
| EntryIndex | FindEntry (const std::string &name) const |
| Finds an entry by name. More... | |
| std::string | EntryName (EntryIndex index) const |
| Returns the name of an archive entry. More... | |
| bool | IsDirEntry (EntryIndex index) const |
| Returns whether an archive entry is a directory. More... | |
| void | ExtractAll (const boost::filesystem::path &targetDir) const |
| Extracts the entire contents of the archive. More... | |
| boost::filesystem::path | ExtractFileTo (EntryIndex index, const boost::filesystem::path &targetDir) const |
| Extracts a single file from the archive, placing it in a specific target directory. More... | |
A class for reading ZIP archives.
Currently, only a limited set of reading operations are supported, and no writing/modification operations.
A ZIP archive is organised as a number of entries, where each entry is a file or a directory. Each entry has a unique integer index, and the indices run consecutively from 0 through EntryCount()-1. For example, a file with 2 file entries and 1 directory entry, i.e. EntryCount() == 3, could look like this:
Index Name
----- ----------------
0 readme.txt
1 images/
2 images/photo.jpg | coral::util::zip::Archive::Archive | ( | const boost::filesystem::path & | path | ) |
Constructor which opens a ZIP archive.
This is equivalent to default construction followed by a call to Open().
| [in] | path | The path to a ZIP archive file. |
| coral::util::zip::Exception | If there was an error opening the archive. |
| void coral::util::zip::Archive::Discard | ( | ) |
Closes the archive.
If no archive is open, this function has no effect.
| std::uint64_t coral::util::zip::Archive::EntryCount | ( | ) | const |
Returns the number of entries in the archive.
This includes both files and directories.
IsOpen() == true | std::string coral::util::zip::Archive::EntryName | ( | EntryIndex | index | ) | const |
Returns the name of an archive entry.
| [in] | index | An archive entry index in the range [0,EntryCount()). |
| coral::util::zip::Exception | If there was an error accessing the archive. |
IsOpen() == true | void coral::util::zip::Archive::ExtractAll | ( | const boost::filesystem::path & | targetDir | ) | const |
Extracts the entire contents of the archive.
This will extract all entries in the archive to the given target directory, recreating the subdirectory structure in the archive.
| [in] | targetDir | The directory to which the files should be extracted. |
| coral::util::zip::Exception | If there was an error accessing the archive. |
| std::ios_base::failure | On I/O error. |
IsOpen() == true | boost::filesystem::path coral::util::zip::Archive::ExtractFileTo | ( | EntryIndex | index, |
| const boost::filesystem::path & | targetDir | ||
| ) | const |
Extracts a single file from the archive, placing it in a specific target directory.
This ignores the directory structure inside the archive, i.e. the file will always be created directly under the given target directory.
| [in] | index | An archive entry index in the range [0,EntryCount()). |
| [in] | targetDir | The directory to which the file should be extracted. |
| coral::util::zip::Exception | If there was an error accessing the archive. |
| std::ios_base::failure | On I/O error. |
IsOpen() == true | EntryIndex coral::util::zip::Archive::FindEntry | ( | const std::string & | name | ) | const |
Finds an entry by name.
| [in] | name | The full name of a file or directory in the archive. The search is case sensitive, and directory names must end with a forward slash (/). |
| coral::util::zip::Exception | If there was an error accessing the archive. |
IsOpen() == true | bool coral::util::zip::Archive::IsDirEntry | ( | EntryIndex | index | ) | const |
Returns whether an archive entry is a directory.
This returns true if and only if the entry has zero size, has a CRC of zero, and a name which ends with a forward slash (/).
| [in] | index | An archive entry index in the range [0,EntryCount()). |
| coral::util::zip::Exception | If there was an error accessing the archive. |
IsOpen() == true | void coral::util::zip::Archive::Open | ( | const boost::filesystem::path & | path | ) |
Opens a ZIP archive.
| [in] | path | The path to a ZIP archive file. |
| coral::util::zip::Exception | If there was an error opening the archive. |
IsOpen() == false
1.8.11