zlib + in memory compression - Raspberry Pi Forums


hi,
looking documentation or example on how use zlib in memory compression.
have multiple buffer save, each of them 2.5 mb. compress them before saving them disk.

trying (in pseudo code :) )

code: select all

[...] char sourcebuffer[2500]; char destbuffer[2500]; [...]  //--- in way sourcebuffer has been populated data zsize=compress(sourcebuffer,destbuffer); //--- expect in way have size of zipp'd buffer fwrite(destbuffer, 1, zsize, myfile);  
thx all!
nicola

something along lines of

code: select all

/* should point memory compress, , it's size */ char *srcbuf; unsigned long srcsize;  /* allocate memory compressed data */ char *dstbuf; unsigned long dstsize;  /* compressed data can larger uncompressed,    returns largest size should needed in worst case. */ dstsize = compressbound(srcsize); dstbuf = malloc(dstsize);  int status = compress(dstbuf, &dstsize, srcbuf, srcsize); if (status == z_ok) {   /* dstbuf pointer compressed version,      dstsize have been updated how big */ } else {   /* there error, ==z_mem_error if ran out of memory      or ==z_buf_error if dst buffer small. */ }  /* once you've done it, free compressed memory */ free(dstbuf); 
can bit more control on speed / size using compress2 5th parameter being integer between 0 (fast, no compression) , 9 (slow, best compression). you'll have more control if use inflate that's more involved.


raspberrypi



Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support