|
Server Help Community forums for Subgame, ASSS, and bots
|
Author |
Message |
Solo Ace Yeah, I'm in touch with reality...we correspond from time to time.
Age:36 Gender: Joined: Feb 06 2004 Posts: 2583 Location: The Netherlands Offline
|
|
Back to top |
|
|
Cyan~Fire I'll count you!
Age:36 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Tue Mar 21, 2006 5:53 pm Post subject: |
|
|
|
|
For zlib, read the comments in zlib.h. That's how I learned, it tells you exactly what to do.
Here's an example from my code both for deflation/inflation (it doesn't use the zlib header though):
int deflate_file(Bytef *in, int length, FILE *out)
{
z_stream strm; //see zlib.h
Bytef compressed[PERL_BUFF]; //This holds our compressed data until we write it.
int code; //holds return values from zlib functions
// Initialize the stream
strm.zalloc = (alloc_func)Z_NULL;
strm.zfree = (free_func)Z_NULL;
strm.next_in = in;
strm.avail_in = length;
code = deflateInit2(&strm, -1, Z_DEFLATED, -15, 9, Z_DEFAULT_STRATEGY);
// Deflate it
while (code == Z_OK)
{
strm.next_out = compressed;
strm.avail_out = PERL_BUFF;
code = deflate(&strm, Z_FINISH);
if (code == Z_OK || code == Z_STREAM_END)
fwrite(compressed, sizeof(Bytef), PERL_BUFF - strm.avail_out, out);
}
// Cleanup & Return
deflateEnd(&strm);
return code;
}
int inflate_file(Bytef *in, int length, FILE *out)
{
z_stream strm;
Bytef uncompressed[PERL_BUFF]; //buffer for decompressed data
int code; //return from zlib funcs
// Initialize the stream
strm.zalloc = (alloc_func)Z_NULL;
strm.zfree = (free_func)Z_NULL;
strm.next_in = in;
strm.avail_in = length;
strm.avail_out = 0; //for the while condition check, not necessary
code = inflateInit2(&strm, -15);
// inflate it
while (code == Z_OK && strm.avail_out == 0)
{
strm.next_out = uncompressed;
strm.avail_out = sizeof(uncompressed);
code = inflate(&strm, Z_SYNC_FLUSH);
switch (code)
{
case Z_OK:
fwrite(uncompressed, sizeof(Bytef),
sizeof(uncompressed), //assume uncompressed is full, so write it all
out);
break;
case Z_STREAM_END:
fwrite(uncompressed, sizeof(Bytef),
sizeof(uncompressed) - strm.avail_out, //can't assume that now
out);
break;
}
}
// Cleanup & Return
inflateEnd(&strm);
return code;
} |
For a nice file, though, you might want to use the built-in gz functions. _________________ This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him. |
|
Back to top |
|
|
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
Software by php BB © php BB Group Server Load: 681 page(s) served in previous 5 minutes.
|