class ZipContainer¶
Overview¶
Zip Container Structure. Based on libzip. More…
#include <zip_container.h> class ZipContainer { public: // structs struct ZipErrorT; struct ZipFileWrapper; // construction ZipContainer(std::string&& data); ZipContainer(std::vector<uint8_t>&& data); ZipContainer(const std::string& path, bool readOnly, bool saveOnDestruct); // methods std::vector<uint8_t> getCompressedData() const; void extractZipFiles(std::string path) const; void saveToDestination(const std::string& dest) const; static ZipContainer compressPath( const std::filesystem::path& path, bool keepRelDirStruct = false ); };
Detailed Documentation¶
Zip Container Structure. Based on libzip.
Construction¶
ZipContainer(std::string&& data)
Constructor. Takes a string argument. This is mainly used for Pistache data receiving.
Parameters:
data |
Zip File Data. Note: Will use entire data.capacity() as ZIP file array, not just data.size() |
Throws |
std::logic_error on failure |
ZipContainer(std::vector<uint8_t>&& data)
Constructor. Initializes zip_t.
Parameters:
data |
Zip data buffer |
Throws |
std::logic_error on failure |
ZipContainer(const std::string& path, bool readOnly, bool saveOnDestruct)
Constructor. Loads data from file at path.
Parameters:
path |
Path to Zip Archive |
readOnly |
Should archive be opened in read-only mode |
saveOnDestruct |
Should the archive be saved automatically on destruct |
Methods¶
std::vector<uint8_t> getCompressedData() const
Get zip archive’s compressed data.
Returns:
Returns compressed data
void extractZipFiles(std::string path) const
Extract Zip Files and store them under path.
Parameters:
path |
Path to extraction directory |
Throws |
std::logic_error on fail |
void saveToDestination(const std::string& dest) const
Save Archive to storage.
Parameters:
dest |
File Name |
Throws |
std::logic_error on fail |
static ZipContainer compressPath( const std::filesystem::path& path, bool keepRelDirStruct = false )
Compress files and directories under path.
Parameters:
path |
Path to directory that should be compressed |
keepRelDirStruct |
Should the created zip archive keep the relative directory structure to path. If false, will save files inside path directly |
Throws |
std::logic_error on fail |
Returns:
Returns ZipContainer with compressed contents