Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bz_decompress.cpp
Go to the documentation of this file.
1 /*
2  * Decompresses Bz2 data
3  *
4  * without parameters reads compressed data from standard input and writes decompressed data to standard output
5  * with 1 parameter reads compressed data from the file given and writes decompressed data to standard output
6  * with 2 parameters reads compressed data from the file in the 1st argument and writes decompressed data to the file in the 2nd argument
7  *
8  */
9 
10 #include <xstream/bz.h>
11 
12 #include <iostream>
13 #include <fstream>
14 
15 using namespace std;;
16 using namespace xstream;;
17 
18 
19 int main(int argc, char* argv[]){
20 
21  const size_t len = 4*1024;
22  char buf[len];
23 
24  istream* readfrom;
25  ostream* writeto;
26 
27  try{
28  /* Binary flags mandtory on win32 systems, otherwise files will be corrupt */
29  if(1<argc){
30  readfrom = new ifstream(argv[1], ios::binary);
31  if(2<argc){
32  writeto = new ofstream(argv[2], ios::binary);
33  }else{
34  writeto = &cout;
35  }
36  }else{
37  readfrom = &cin;
38  writeto = &cout;
39  }
40 
41  bz::istreambuf bz_i(readfrom->rdbuf());
42  istream bzin(&bz_i);
43 
44  //raise exceptions
45  bzin.exceptions(ios::badbit);
46 
47  while(bzin.good()){
48  bzin.read(buf,len);
49  writeto->write(buf,bzin.gcount());
50  }
51 
52  }
53  catch(exception& e){
54  cerr<<"Error: "<<e.what()<<endl;
55  }
56 
57  writeto->flush();
58 
59  //pointers not being freed
60 
61  return 0;
62 }
TEllipse * e
C++ streambuf interface to read and write bzip2 streams.
int main(int argc, char *argv[])
Definition: gendoc.cc:6