tags:

views:

302

answers:

1

I am writing a program that downloads tar.xz files from a server and extracts them in a certain place. I am struggling to find a away of extracting the tar.xz file in the certain place. I am using Qt so a more Qt-way of doing it would be useful, but I don't really mind.

+1  A: 

There is no support for archives in Qt. You can either have a look at the KDE library which offers support for virtual file systems or you can use QProcess to call tar directly. Use -C <dir> (uppercase C) to specify the directory to extract to.

[EDIT] There also is libtar (BSD license).

Aaron Digulla
I would prefere not to use QProcess because I would like my application to run on windows as well and using QProcess would mean I would have to ship with tar for windows. Maybe someone could give me a tutorial on liblzma.
TomMan
That lib won't allow you to read the tar archive. If ".xz" is not a typo, then liblzma will only allow you to decompress the archive. But usually tar archives are compressed with bzip2 (.bz2) or gzip (.gz). For these, you probably need other libraries.
Aaron Digulla
I believe I can use zlib to extract the tar, is this correct.
TomMan
Yes but you have *two* containers inside of each other. You have the GZip container and inside of that a Tar container. Unzipping the file just gives you an uncompressed tar archive. How do you plan to read the files from that?
Aaron Digulla
Not sure, it must be possible though because gnu tar can do it.
TomMan
Then you must turn the source for tar into a library and link your code against it :-) Note that GNU tar is GPL so if you use that, your product will also be GPL'd.
Aaron Digulla
I've found something called libtar that may help me.
TomMan
Yep, http://www.feep.net/libtar/ seems to be what you're looking for.
Aaron Digulla