Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
b64_decode.cpp
Go to the documentation of this file.
1 /*
2  * Base64 decode data
3  *
4  * without parameters reads encoded data from standard input and writes decoded data to standard output
5  * with 1 parameter reads encoded data from the file given and writes decoded data to standard output
6  * with 2 parameters reads encoded data from the file in the 1st argument and writes decoded data to the file in the 2nd argument
7  *
8  */
9 
10 #include <xstream/base64.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  if(1<argc){
29  readfrom = new ifstream(argv[1]);
30  if(2<argc){
31  writeto = new ofstream(argv[2]);
32  }else{
33  writeto = &cout;
34  }
35  }else{
36  readfrom = &cin;
37  writeto = &cout;
38  }
39 
40  base64::istreambuf b64sb(readfrom->rdbuf());
41  istream b64(&b64sb);
42 
43  //raise exceptions
44  b64.exceptions(ios::badbit);
45 
46  while(b64.good()){
47  b64.read(buf,len);
48  writeto->write(buf,b64.gcount());
49  }
50 
51  b64.sync();
52  writeto->flush();
53 
54  }
55 
56  catch(exception& e){
57  cerr<<"Error: "<<e.what()<<endl;
58  }
59 
60 
61  //pointers not being freed
62 
63  return 0;
64 }
TEllipse * e
C++ streambuf interface to encode/decode base64 data.
Base64 decode stream class.
Definition: base64.h:106
int main(int argc, char *argv[])
Definition: gendoc.cc:6