boost::iostreams::gzip_compressor and multiple files
I have been experimenting with the boost::iostreams to create a gzip file, for example the following works fine: using namespace boost::iostreams; filtering_ostream out; out.push(gzip_compressor()); out.push(file_sink("test.gz", std::ios::binary)); out << "This is a gz file\n"; This will create a gz file containing a single compressed file (called 'test'). I can change the name of this internal file using a gzip_params struct and all is well. However, I want to create a single gzip file that contains multiple compressed files, each with a different filename. Does anyone know how to achieve this? Thanks in advance.
Unfortunately, this is beyond the capability of the gzip file format. You might try looking up the "tar" file format (a good starting point might be http://en.wikipedia.org/wiki/Tar.gz). One would normally use tar to group the files together into a single data stream, and then use gzip to compress that stream.
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Robert Caldecott Sent: Thursday, August 09, 2007 6:33 AM To: boost-users@lists.boost.org Subject: [Boost-users] boost::iostreams::gzip_compressor and multiple files
I have been experimenting with the boost::iostreams to create a gzip file, for example the following works fine:
using namespace boost::iostreams; filtering_ostream out; out.push(gzip_compressor()); out.push(file_sink("test.gz", std::ios::binary)); out << "This is a gz file\n";
This will create a gz file containing a single compressed file (called 'test'). I can change the name of this internal file using a gzip_params struct and all is well.
However, I want to create a single gzip file that contains multiple compressed files, each with a different filename. Does anyone know how to achieve this?
Thanks in advance.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Thu, 9 Aug 2007, Robert Caldecott wrote:
I have been experimenting with the boost::iostreams to create a gzip file, for example the following works fine:
using namespace boost::iostreams; filtering_ostream out; out.push(gzip_compressor()); out.push(file_sink("test.gz", std::ios::binary)); out << "This is a gz file\n";
This will create a gz file containing a single compressed file (called 'test'). I can change the name of this internal file using a gzip_params struct and all is well.
However, I want to create a single gzip file that contains multiple compressed files, each with a different filename. Does anyone know how to achieve this?
I guess that when you uncompress the file (e.g. with gunzip), you want to get all those named files in, well, different files? As far as I know, the gzip format doesn't allow that (I could be wrong), hence the gzip'ed tar files we often see. I can't think of any simple portable solution aside from creating each file regularly and then calling system("tar zcf filename.tar.gz ..."); and finally remove the uncompressed files. That would require that 'tar' is available the system your software is run on. Anyone else has any better ideas? -- François Duranleau LIGUM, Université de Montréal
On 8/9/07, François Duranleau
On Thu, 9 Aug 2007, Robert Caldecott wrote:
I have been experimenting with the boost::iostreams to create a gzip file, for example the following works fine:
using namespace boost::iostreams; filtering_ostream out; out.push(gzip_compressor()); out.push(file_sink("test.gz", std::ios::binary)); out << "This is a gz file\n";
This will create a gz file containing a single compressed file (called 'test'). I can change the name of this internal file using a gzip_params struct and all is well.
However, I want to create a single gzip file that contains multiple compressed files, each with a different filename. Does anyone know how to achieve this?
I guess that when you uncompress the file (e.g. with gunzip), you want to get all those named files in, well, different files? As far as I know, the gzip format doesn't allow that (I could be wrong), hence the gzip'ed tar files we often see. I can't think of any simple portable solution aside from creating each file regularly and then calling
system("tar zcf filename.tar.gz ...");
and finally remove the uncompressed files. That would require that 'tar' is available the system your software is run on.
Anyone else has any better ideas?
Read the tar specs and write the code to generate headers/tailers yourself. It's probably quite simple, especially the writing part.
On Thu, Aug 09, 2007 at 11:38:58AM -0400, François Duranleau wrote:
On Thu, 9 Aug 2007, Robert Caldecott wrote:
However, I want to create a single gzip file that contains multiple compressed files, each with a different filename. Does anyone know how to achieve this?
I guess that when you uncompress the file (e.g. with gunzip), you want to get all those named files in, well, different files? As far as I know, the gzip format doesn't allow that (I could be wrong), hence the gzip'ed tar
Right, it doesn't allow it and this is fine. Why should gzip allow archiving multiple files? It is a compressing program, not more. It's again the usual (and fine) Unix philosophy: one program for a simple task, combine/pipe multiple such simple programs to get more complex tasks done. This way you can also compress via gzip other archive formats, do not increase the code base of gzip and make compressing alone usable for other programs as well (which do not require tar). I would wish such a solution would be used on the proprietary systems which use ZIP as default archiver as well ... Jens
participants (5)
-
Andrew Holden
-
François Duranleau
-
Jens Seidel
-
Olaf van der Spek
-
Robert Caldecott