dataSizeToString can print the exact size additionally

This commit is contained in:
Martchus 2015-08-09 23:58:13 +02:00
parent 72b7afb17e
commit 8c6f7a9785
2 changed files with 5 additions and 2 deletions

View File

@ -25,7 +25,7 @@ void truncateString(string &str, char terminationChar)
* *
* The unit with appropriate binary prefix will be appended. * The unit with appropriate binary prefix will be appended.
*/ */
string dataSizeToString(uint64 sizeInByte) string dataSizeToString(uint64 sizeInByte, bool includeByte)
{ {
stringstream res(stringstream::in | stringstream::out); stringstream res(stringstream::in | stringstream::out);
res.setf(ios::fixed, ios::floatfield); res.setf(ios::fixed, ios::floatfield);
@ -41,6 +41,9 @@ string dataSizeToString(uint64 sizeInByte)
} else { } else {
res << (static_cast<double>(sizeInByte) / 1099511627776.0) << " TiB"; res << (static_cast<double>(sizeInByte) / 1099511627776.0) << " TiB";
} }
if(includeByte && sizeInByte > 1024LL) {
res << ' ' << '(' << sizeInByte << " byte)";
}
return res.str(); return res.str();
} }

View File

@ -194,7 +194,7 @@ template <typename T> LIB_EXPORT std::string interpretIntegerAsString(T integer,
return std::string(buffer + startOffset, sizeof(T) - startOffset); return std::string(buffer + startOffset, sizeof(T) - startOffset);
} }
LIB_EXPORT std::string dataSizeToString(uint64 sizeInByte); LIB_EXPORT std::string dataSizeToString(uint64 sizeInByte, bool includeByte = false);
LIB_EXPORT std::string bitrateToString(double speedInKbitsPerSecond, bool useByteInsteadOfBits = false); LIB_EXPORT std::string bitrateToString(double speedInKbitsPerSecond, bool useByteInsteadOfBits = false);
LIB_EXPORT std::string encodeBase64(const std::vector<char> &bytes); LIB_EXPORT std::string encodeBase64(const std::vector<char> &bytes);
LIB_EXPORT std::vector<char> decodeBase64(const std::string &encoded); LIB_EXPORT std::vector<char> decodeBase64(const std::string &encoded);