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
2010-07-27 12:38:39
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
2010-07-27 13:03:41
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
2010-07-27 13:06:13
I believe I can use zlib to extract the tar, is this correct.
TomMan
2010-07-27 13:07:54
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
2010-07-27 13:19:34
Not sure, it must be possible though because gnu tar can do it.
TomMan
2010-07-27 13:22:21
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
2010-07-27 13:25:37
I've found something called libtar that may help me.
TomMan
2010-07-27 13:37:35
Yep, http://www.feep.net/libtar/ seems to be what you're looking for.
Aaron Digulla
2010-07-27 13:43:38