Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I decompress tar.gz file using c++ program

Tags:

c++

In my linux program, I want to decompress a tar.gz file contents to a specific directory. Is there any system call or any C++ class available in C/C++ to extract file contents from tar.gz file?

like image 337
user3793746 Avatar asked Jul 03 '14 06:07

user3793746


People also ask

What does the tar C command do?

The tar command manipulates archives by writing files to, or retrieving files from an archive storage medium. The files used by the tar command are represented by the File parameter.

Can 7zip decompress gz?

The main features of 7-Zip Supported formats: Packing / unpacking: 7z, XZ, BZIP2, GZIP, TAR, ZIP and WIM.


1 Answers

There is excellent library libarchive, which supports accessing multiple archive formats using consistent API. You can follow these examples on how to use it.

If you are on Ubuntu, you can easily install this library using command sudo apt-get install libarchive-dev. On other platforms, you may need to download source code and compile this library yourself.

One advantage of using libarchive vs. using system() calls is not depending on system utilities, and also it should work faster because it does not fork.

like image 166
mvp Avatar answered Oct 16 '22 12:10

mvp