Question : Even more questions about compression/decompression.

Hi Experts!
I got to where I wanted to be with the help of my last two questions here (Actually I'm amazed with this site, keep up the good work).
Now on with some more questions about Compression and Decompression.

If you want to take a look at the code of my test program, it is attached here.

Well, with my test program I've got to know how compress and decompress works with boost.iostreams. Now I'm looking for a way for it to compress and decompress without me having to tell what the destination file will be. Since I'll be implementing this in a larger program of log analysis, I need the whole process of compress and decompress to be automatic.
Also, if you Experts can point me to a way to make this little program scan a directory for ".z"  files and decompress them all, it would be a lot helpful.
Reviewing what I need you guys to help me with:
Scan directory for ".z" files, decompress them all, compress the files as they get analysed one by one.

One last thing, if you know of any compression method I can use with boost.iostreams that is more efficient, please let me know. The analysis program I'll be implementing this compress and decompress functionality deals with loads of data of log files, so it would be nice to have a stronger compression method.

Thanks in advance.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
#include <fstream>
#include <iostream>

#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include <boost/iostreams/filtering_stream.hpp>

using namespace std;
using namespace boost::iostreams;

//---------------------------------------------------------------------
void compress (string arq, string arqdest)
{
    ifstream in(arq.c_str(), ios_base::in | ios_base::binary);
    ofstream file(arqdest.c_str(), ios_base::out | ios_base::binary);
    filtering_streambuf<output> out;
    out.push(zlib_compressor());
    out.push(file);
    boost::iostreams::copy(in, out);
}

//---------------------------------------------------------------------
void decompress (string arqdest, string arq)
{
    ifstream file(arqdest.c_str(), ios_base::in | ios_base::binary);
    ofstream out(arq.c_str(), ios_base::out | ios_base::binary);
    filtering_streambuf<input> in;
    in.push(zlib_decompressor());
    in.push(file);
    boost::iostreams::copy(in, out);
}
//---------------------------------------------------------------------
int main()
{
    string arq;
    string arqdest;
    char mode;

    cout << "Compress = 'c' / Descompress = 'd'" << endl;
    cout << "Choose one of the methods: " << endl;
    cin >> mode;
    if(mode == 'd')
    {
       cout << "Enter the file to be decompressed: " << endl;
       cin >> arqdest;
       cout << "Enter the destination file: " << endl;
       cin >> arq;
       decompress(arqdest, arq);
    }
    if(mode == 'c')
    {
       cout << "Enter the file to be compressed: " << endl;
       cin >> arq;
       cout << "Enter the destination file: " << endl;
       cin >> arqdest;
       compress(arq, arqdest);
    }

    return 0;

}

Answer : Even more questions about compression/decompression.

>> Scan directory for ".z" files, decompress them all, compress the files as they get analysed one by one.

Are you modifying the data ? If not, you can leave out the compression step. Just simply decompress the stream, and process it.


>> Now I'm looking for a way for it to compress and decompress without me having to tell what the destination file will be.

If you want to save it to a file, you'll still need to somehow come up with a filename. What filename do you want to use ? You could use the filename of the source file, and change the extension eg., or add a suffix, or ...
Alternatively, you could use an automatically generated temporary filename using tmpnam (http://www.cplusplus.com/reference/clibrary/cstdio/tmpnam/) eg.
Random Solutions  
 
programming4us programming4us