Browse Source

- added oxum_t

- added oxum_of_file()
- added oxum_of_filelist()
master
parent
commit
fa39846b34
  1. 6
      src/include/checksum.hpp
  2. 27
      src/lib/checksum.cpp

6
src/include/checksum.hpp

@ -7,6 +7,10 @@
using namespace std;
enum checksum_algorithms {md5=1, sha1};
typedef struct {
long unsigned int octetcount;
long unsigned int streamcount;
} oxum_t;
class Checksum {
public:
@ -14,6 +18,8 @@ class Checksum {
//list<string> get_supported_checksum_algorithms();
//bool is_algorithm_supported( string alg );
string checksum_of_file(string filepath, checksum_algorithms alg);
oxum_t oxum_of_file(string filepath);
oxum_t oxum_of_filelist( list<string> filepaths);
};
#endif

27
src/lib/checksum.cpp

@ -42,4 +42,31 @@ string Checksum::checksum_of_file(string filepath, checksum_algorithms alg) {
return hex_result.str();
}
oxum_t Checksum::oxum_of_file(string filepath) {
ifstream file (filepath, ios::ate);
oxum_t oxum;
if (file.is_open() ) {
ifstream::pos_type fileSize;
fileSize = file.tellg();
oxum.octetcount = fileSize;
oxum.streamcount = 1;
file.close();
} else {
cout << "file '"<< filepath << "' could not be opened" << endl;
}
return oxum;
}
oxum_t Checksum::oxum_of_filelist( list<string> files) {
oxum_t oxum;
oxum.octetcount=0;
oxum.streamcount=0;
list<string>::iterator i;
for (i=files.begin(); i!= files.end(); i++) {
oxum_t tmp = this->oxum_of_file( *i );
oxum.octetcount+= tmp.octetcount;
oxum.streamcount+= tmp.streamcount;
}
return oxum;
}
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab
Loading…
Cancel
Save