How do I zip a directory or multple files with zlib, using C/C++?

I did search for this topic, but I didn't find any relevant clue for this.

Can anyone give me some tips or demo code that can solve the problem?

Thanks in advance.

---FYI---

What I wanna do here is to zip files and upload to remote PC. I think it'll take the following steps:

a) initialize a zipped file head and send to remote PC and save that zipped file head.

b) open file to read a portion of file data and zip the file data locally.

c) send zipped data through a pipe (tcp or udp for example) to remote PC.

d) save the data from pipe, which is zipped, on the remote PC.

e) if there are multiple files, come back to b)

e) when all files is zipped and transferred to remote PC, then close zipped file.

Two question here:

a) compress/decompress

b) File format

Thanks guys!

Answers


zlib zips a single stream. If you want to zip multiple files, you need to do one of two things:

  • Define a format (or use an existing format) that combines multiple files into one stream, then zip that; or
  • Zip each file individually, then use some format to combine those into one output file.

If you take the first option, using the existing tar format to combine the files, you will be producing a .tar.Z file which can be extracted with standard tools, so this is a good way to go. You can use libtar to generate a tar archive.


Need Your Help

MVC and the Repository Pattern: Roles of Controllers, Models, and Repositories?

php model-view-controller design-patterns repository-pattern

So I've been studying the role of the repository pattern as a means of decoupling the persistence layer from my models in an MVC framework. Prior to this, I might have my UserModel calling active r...

Magento joining two tables with different columns

magento-1.4 magento-1.5 magento

i have to modify an adminhtml section for stock alerts. normally for a single product there's a retrieve of registered customer which have subscribed to alerts by this function:

Download a webpage in UTF-8

c# .net utf-8

I'm using the code below to download this XML file: