[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 726
  • Last Modified:

zlib uncompression

In a program, I've imported the call "uncompress()" from zlib.dll using LoadLibrary(), then GetProcAddress() with the handle returned by LoadLibrary().  So now that I have support to call the function uncompress() from zlib.dll, how do I uncompress an entire file?  For 500 points, I wanna see code example that I can copy and paste (with relatively few modifications) :)

Thanks!
Chris O.
0
core123
Asked:
core123
  • 2
1 Solution
 
PIGCommented:
HINSTANCE instance = LoadLibrary("zlib.dll");
FARPROC uncomp = GetProcAddress(instance, "uncompress");
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
compr = yourData;
comprLen = uncomprLen = yourDataSize;
uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
err = uncomp(uncompr, &uncomprLen, compr, comprLen);

If You want there is source of zlib
//ftp.uu.net/pub/archiving/zip/zlib/
0
 
core123Author Commented:
Arg, but how would I use that with a file? I want this spoon-fed to me!
0
 
PIGCommented:
FILE* fileIn =  fopen("YourFileIn.XXX", "r");
FILE* fileOut =  fopen("YourFileOut.XXX", "w");
while (TRUE){
  Byte bufferIn[1024];
  uLong readB = fread((void*)bufferIn, 1024, 1, fileIn);
  if (!readB) break;
  Byte bufferOt[1024];
  uLong writeB = 0;
  YourUnompressFunction(bufferIn, readB, bufferOut, writeB);
  uLong realWB = fwrite(bufferOut, writeB, 1, fileOut);
  if ((readB < 1024) || (realWB < writeB)) break;
}
fclose(fileIn);
fclose(fileOut);
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now