From fa39846b34e6edf72986ff2e7233dcabf7b6cf00 Mon Sep 17 00:00:00 2001 From: "art1@andreas-romeyke.de" Date: Fri, 1 Jun 2018 15:41:20 +0200 Subject: [PATCH] - added oxum_t - added oxum_of_file() - added oxum_of_filelist() --- src/include/checksum.hpp | 6 ++++++ src/lib/checksum.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/include/checksum.hpp b/src/include/checksum.hpp index 276c0de..2db9a36 100644 --- a/src/include/checksum.hpp +++ b/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 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 filepaths); }; #endif diff --git a/src/lib/checksum.cpp b/src/lib/checksum.cpp index f1d3b94..9be0674 100644 --- a/src/lib/checksum.cpp +++ b/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 files) { +oxum_t oxum; +oxum.octetcount=0; +oxum.streamcount=0; +list::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