c - Compress data to chunks using Zlib -


i want compress file size > 50mb zlib. want compressed file in chunks (for example, 32kb chunks).

i don't want read 32kb of uncompressed file , compress it. compressed file should contain 32kb compressed chunks. compression should reset after avail_out = 32kb.

i need zlib , random access.

this have far:

do {     strm.avail_in = fread(in, 1, chunk, source);      flush = feof(source) ? z_finish : z_full_flush;     strm.next_in = in;     strm.next_out = out;      strm.avail_out = chunk;     deflate(&strm, flush);      if (strm.avail_out == 0)         have = tmp;     else         have = chunk - strm.avail_out;      fwrite(out, 1, have, dest);      tmp = strm.avail_out;      if (tmp == 0)         deflatereset(&strm);  } while (flush != z_finish); 

but there several problems in code.

  1. when reset compression every 32kb, lose compressed bytes haven't been written yet because avail_out full; , if try write them compressed chunk wouldn't 32kb anymore.

  2. if knew how data has been compressed when avail_out filled, reset file position , begin compression there.

it not possible assure can fill desired size, can close. see fitblk.c how it.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -