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.


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!


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

How to load a class from a .cs file

c# reflection c#-4.0 dynamic

Is it possible to load a class and create Instance of it from It's .cs file?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.