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 ) thx all!
nicola
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);
nicola
something along lines of 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.
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);
raspberrypi
Comments
Post a Comment