You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.4 KiB
53 lines
1.4 KiB
#include "libzip.h"
|
|
#include <malloc.h>
|
|
|
|
zipDataPackage::zipDataPackage(){
|
|
m_bCtxBusy = true;
|
|
m_pZipCtx = (z_stream *) malloc(sizeof(z_stream));
|
|
if(m_pZipCtx!=NULL) {
|
|
m_pZipCtx->zalloc = Z_NULL;
|
|
m_pZipCtx->zfree = Z_NULL;
|
|
m_pZipCtx->opaque = Z_NULL;
|
|
m_bCtxBusy = false;
|
|
};
|
|
};
|
|
|
|
zipDataPackage::~zipDataPackage(){
|
|
if(m_pZipCtx!= NULL) free(m_pZipCtx);
|
|
};
|
|
|
|
bool zipDataPackage::zip( uint8_t *data_in, size_t size_in, uint8_t *&data_out, size_t &size_out ){
|
|
if(!m_bCtxBusy) {
|
|
m_bCtxBusy = true;
|
|
m_pZipCtx->avail_in = size_in;
|
|
m_pZipCtx->next_in = data_in;
|
|
size_out = 0;
|
|
data_out = (uint8_t*) malloc(size_in);
|
|
if( data_out!= NULL ) {
|
|
m_pZipCtx->next_out = data_out;
|
|
m_pZipCtx->avail_out = size_in;
|
|
deflateInit( m_pZipCtx, Z_BEST_COMPRESSION);
|
|
deflate( m_pZipCtx, Z_FINISH);
|
|
deflateEnd( m_pZipCtx);
|
|
size_out = m_pZipCtx->total_out;
|
|
return !(m_bCtxBusy=false);
|
|
};
|
|
};
|
|
return false;
|
|
};
|
|
|
|
bool zipDataPackage::unzip( uint8_t *data_in, size_t size_in, uint8_t *&data_out, size_t &size_out ){
|
|
if(!m_bCtxBusy) {
|
|
m_bCtxBusy = true;
|
|
if( data_out == NULL ) {
|
|
data_out = (uint8_t*) malloc( size_in * 10 );
|
|
};
|
|
inflateInit( m_pZipCtx);
|
|
inflate( m_pZipCtx, Z_NO_FLUSH);
|
|
inflateEnd( m_pZipCtx);
|
|
size_out = m_pZipCtx->total_out;
|
|
data_out = (uint8_t*)realloc(data_out,size_out);
|
|
return !(m_bCtxBusy=false);
|
|
};
|
|
return false;
|
|
};
|