53 lines
1.2 KiB
C++
53 lines
1.2 KiB
C++
|
#include "Zip.h"
|
||
|
#include "zip/zip.h"
|
||
|
|
||
|
namespace VariableEditor {
|
||
|
|
||
|
Zip::Zip(const std::string & filename){
|
||
|
//zip = zip_open(filename.c_str(), ZIP_DEFAULT_COMPRESSION_LEVEL, 'w');
|
||
|
zip = zip_stream_open(NULL, 0, ZIP_DEFAULT_COMPRESSION_LEVEL, 'w');
|
||
|
}
|
||
|
|
||
|
Zip::~Zip(){
|
||
|
if(!closed){
|
||
|
this->close();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Zip::addFile(const std::string & filename){
|
||
|
zip_entry_open(zip, filename.c_str());
|
||
|
{
|
||
|
zip_entry_fwrite(zip, filename.c_str());
|
||
|
}
|
||
|
zip_entry_close(zip);
|
||
|
}
|
||
|
|
||
|
void Zip::addBuffer(std::string filename, char * inbuf, size_t inbufsize){
|
||
|
zip_entry_open(zip, filename.c_str());
|
||
|
{
|
||
|
zip_entry_write(zip, inbuf, inbufsize);
|
||
|
}
|
||
|
zip_entry_close(zip);
|
||
|
}
|
||
|
|
||
|
void Zip::getOutputBuffer(char * * outbuf, size_t & outbufsize){
|
||
|
zip_stream_copy(zip, (void * *)outbuf, &outbufsize);
|
||
|
}
|
||
|
|
||
|
void Zip::close(){
|
||
|
std::cout << "close zip" << std::endl;
|
||
|
zip_stream_close(zip);
|
||
|
closed = true;
|
||
|
}
|
||
|
|
||
|
UnZip::UnZip(const std::string & filename, const std::string & outdir) {
|
||
|
//zip = zip_open(filename.c_str(), ZIP_DEFAULT_COMPRESSION_LEVEL, 'r');
|
||
|
zip_extract(filename.c_str(), outdir.c_str(), NULL, NULL);
|
||
|
//zip_stream_extract(inbuf, inbufsize, outdir.c_str(), NULL, NULL);
|
||
|
//free(inbuf);
|
||
|
}
|
||
|
|
||
|
UnZip::~UnZip() {};
|
||
|
|
||
|
}
|