Skip to content

Commit

Permalink
now integrated with jsonlab
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed May 1, 2019
1 parent 68d8815 commit d6a48c6
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/zmat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const char *metadata[]={"ArrayType","ArraySize"};
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
TZipMethod zipid=zmZlib;
int iscompress=1;
const char *zipmethods[]={"zlib","gzip"};
const char *zipmethods[]={"zlib","gzip",""};

/**
* If no input is given for this function, it prints help information and return.
Expand All @@ -58,10 +58,10 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
iscompress=val[0];
}
if(nrhs>=3){
int len=mxGetNumberOfElements(prhs[1]);
if(!mxIsChar(prhs[1]) || len==0)
int len=mxGetNumberOfElements(prhs[2]);
if(!mxIsChar(prhs[2]) || len==0)
mexErrMsgTxt("the 'method' field must be a non-empty string");
if((zipid=(TZipMethod)zmat_keylookup((char *)mxGetChars(plhs[1]), zipmethods))<0)
if((zipid=(TZipMethod)zmat_keylookup((char *)mxArrayToString(prhs[2]), zipmethods))<0)
mexErrMsgTxt("the specified compression method is not supported");
}

Expand All @@ -72,6 +72,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
dimtype inputsize=mxGetNumberOfElements(prhs[0]);
dimtype buflen[2]={0};
unsigned char *temp=NULL;
char * inputstr=(mxIsChar(prhs[0])? mxArrayToString(prhs[0]) : (char *)mxGetChars(prhs[0]));

zs.zalloc = Z_NULL;
zs.zfree = Z_NULL;
Expand All @@ -91,14 +92,14 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
temp=(unsigned char *)malloc(buflen[0]);

zs.avail_in = inputsize; // size of input, string + terminator
zs.next_in = (Bytef *)(mxGetChars(prhs[0])); // input char array
zs.next_in = (Bytef *)inputstr; // input char array
zs.avail_out = buflen[0]; // size of output

zs.next_out = (Bytef *)(temp); //(Bytef *)(); // output char array

ret=deflate(&zs, Z_FINISH);
if(ret!=Z_STREAM_END && ret!=Z_OK)
mexErrMsgTxt("not all input data is compressed");
mexErrMsgTxt("invalid input buffer");
deflateEnd(&zs);
}else{
if(zipid==zmZlib){
Expand All @@ -119,7 +120,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){

ret=inflate(&zs, Z_FINISH);
if(ret!=Z_STREAM_END && ret!=Z_OK)
mexErrMsgTxt("not all input data is decompressed");
mexErrMsgTxt("invalid input buffer");
inflateEnd(&zs);
}
if(temp){
Expand Down

0 comments on commit d6a48c6

Please sign in to comment.