Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
adler.cpp
Go to the documentation of this file.
1 /*
2  * calculates adler32 checksum of standard input or file in the 1st parameter
3  *
4  */
5 
6 #include <xstream/digest.h>
7 
8 #include <iostream>
9 #include <fstream>
10 
11 using namespace std;;
12 using namespace xstream;;
13 
14 
15 int main(int argc, char* argv[]){
16 
17  const size_t len = 4*1024;
18  char buf[len];
19 
20  istream* readfrom;
21 
22  try{
23  if(1<argc){
24  readfrom = new ifstream(argv[1]);
25  }else{
26  readfrom = &cin;
27  }
28 
29  digest::adler32 ad;
30  ostream out(&ad);
31 
32  //raise exceptions
33  out.exceptions(ios::badbit);
34 
35 
36  while(readfrom->good()){
37  readfrom->read(buf,len);
38  out.write(buf,readfrom->gcount());
39  }
40 
41  out.flush();
42  clog<<"Adler32 = "<< (ad.digest()) <<endl;
43 
44  }
45  catch(exception& e){
46  cerr<<"Error: "<<e.what()<<endl;
47  }
48 
49 
50  //pointers not being freed
51 
52  return 0;
53 }
C++ objects to calculate digests of data.
TEllipse * e
int main(int argc, char *argv[])
Definition: gendoc.cc:6