33 lines
883 B
C++
33 lines
883 B
C++
#include "file.h"
|
|
|
|
#include <iomanip>
|
|
|
|
FileSize::FileSize(uint64_t fs) : fs(fs) {}
|
|
|
|
File::File(uint64_t fs, uint64_t inode, uint64_t linkcount, const std::string& path) :
|
|
filesize(fs), inode(inode), linkcount(linkcount), path(path) {}
|
|
|
|
Hash File::createHash() {
|
|
Hash hash;
|
|
Hash::create(hash, path);
|
|
return hash;
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& str, const FileSize& fs) {
|
|
static const char PREFIX[] {' ', 'K', 'M', 'G', 'T', 'P', 'E'};
|
|
static const uint_fast8_t PREFIXCOUNT = 7;
|
|
static const uint_fast32_t FACTOR = 1000;
|
|
static const uint_fast32_t COMMA = 100; // nach komma stellen
|
|
uint64_t cpy = fs.fs * COMMA;
|
|
uint_fast8_t prefix = 0;
|
|
while(cpy > (FACTOR * 3 * COMMA) && prefix < PREFIXCOUNT) {
|
|
cpy /= FACTOR;
|
|
++prefix;
|
|
}
|
|
|
|
str << std::setprecision(2) << std::fixed << (cpy / (float) COMMA);
|
|
if(prefix > 0)
|
|
str << PREFIX[prefix];
|
|
return str << "B";
|
|
}
|