NRP Core  1.4.1
ZipContainer Class Reference

Zip Container Structure. Based on libzip. More...

#include <zip_container.h>

Public Member Functions

 ZipContainer (std::string &&data)
 Constructor. Takes a string argument. This is mainly used for Pistache data receiving. More...
 
 ZipContainer (std::vector< uint8_t > &&data)
 Constructor. Initializes zip_t. More...
 
 ZipContainer (const std::string &path, bool readOnly, bool saveOnDestruct)
 Constructor. Loads data from file at path. More...
 
 ~ZipContainer () noexcept
 Destructor. Will save zip archive if requested. More...
 
std::vector< uint8_t > getCompressedData () const
 Get zip archive's compressed data. More...
 
void extractZipFiles (std::string path) const
 Extract Zip Files and store them under path. More...
 
void saveToDestination (const std::string &dest) const
 Save Archive to storage. More...
 

Static Public Member Functions

static ZipContainer compressPath (const std::filesystem::path &path, bool keepRelDirStruct=false)
 Compress files and directories under path. More...
 

Detailed Description

Zip Container Structure. Based on libzip.

Constructor & Destructor Documentation

◆ ZipContainer() [1/3]

ZipContainer::ZipContainer ( std::string &&  data)

Constructor. Takes a string argument. This is mainly used for Pistache data receiving.

Parameters
dataZip File Data. Note: Will use entire data.capacity() as ZIP file array, not just data.size()
Exceptions
Throwsstd::logic_error on failure

◆ ZipContainer() [2/3]

ZipContainer::ZipContainer ( std::vector< uint8_t > &&  data)

Constructor. Initializes zip_t.

Parameters
dataZip data buffer
Exceptions
Throwsstd::logic_error on failure

◆ ZipContainer() [3/3]

ZipContainer::ZipContainer ( const std::string &  path,
bool  readOnly,
bool  saveOnDestruct 
)

Constructor. Loads data from file at path.

Parameters
pathPath to Zip Archive
readOnlyShould archive be opened in read-only mode
saveOnDestructShould the archive be saved automatically on destruct

◆ ~ZipContainer()

ZipContainer::~ZipContainer ( )
noexcept

Destructor. Will save zip archive if requested.

Member Function Documentation

◆ compressPath()

ZipContainer ZipContainer::compressPath ( const std::filesystem::path &  path,
bool  keepRelDirStruct = false 
)
static

Compress files and directories under path.

Parameters
pathPath to directory that should be compressed
keepRelDirStructShould the created zip archive keep the relative directory structure to path. If false, will save files inside path directly
Returns
Returns ZipContainer with compressed contents
Exceptions
Throwsstd::logic_error on fail

◆ extractZipFiles()

void ZipContainer::extractZipFiles ( std::string  path) const

Extract Zip Files and store them under path.

Parameters
pathPath to extraction directory
Exceptions
Throwsstd::logic_error on fail

◆ getCompressedData()

std::vector< uint8_t > ZipContainer::getCompressedData ( ) const

Get zip archive's compressed data.

Returns
Returns compressed data

◆ saveToDestination()

void ZipContainer::saveToDestination ( const std::string &  dest) const

Save Archive to storage.

Parameters
destFile Name
Exceptions
Throwsstd::logic_error on fail

The documentation for this class was generated from the following files: