Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Creating a ZIP archive and adding files to it

 
Post new topic   Reply to topic Printable version
 View previous topic  TCP help Post :: Post First C++ project [Uh-oh]  View next topic  
Author Message
Solo Ace
Yeah, I'm in touch with reality...we correspond from time to time.


Age:31
Gender:Gender:Male
Joined: Feb 06 2004
Posts: 2583
Location: The Netherlands
Offline

PostPosted: Tue Mar 21, 2006 4:20 pm    Post subject: Creating a ZIP archive and adding files to it Reply to topic Reply with quote

Before I'm wasting more time and energy on this I'll just ask here.

I want my (C++) program to create a ZIP and/or CAB archive file and put a bunch of files in it.
The files have to be readable by Windows Explorer and some automated system somewhere else.

I'm trying to figure out how to use Zlib, but I didn't get much further than
Code: Show/Hide
      z_stream zstm;
      memset(&zstm, 0, sizeof(z_stream));
      deflateInit(&zstm, Z_DEFAULT_COMPRESSION);


and I have no idea if this is the right direction I'm going.

I see all these great bloated libraries for file compression on the web!

What should I do?
Give me some examples or something, please.

I refuse to system() or CreateProcess() a 7zip exe! (The thought of that might even make some of you vomit icon_smile.gif ).
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:30
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Tue Mar 21, 2006 5:53 pm    Post subject: Reply to topic Reply with quote

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):
Code: Show/Hide
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
View users profile Send private message Add User to Ignore List Visit posters website
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Non-Subspace Related Coding All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 46 page(s) served in previous 5 minutes.

phpBB Created this page in 0.087308 seconds : 26 queries executed (44.0%): GZIP compression disabled