#include "Utils.hpp"
#include <iostream>
#include <string>

namespace Li {
	std::string Utils::HumanReadableByteStr(uint64_t bytes)
	{
		const char* suffix[5] = { "B", "KB", "MB", "GB", "TB" };
		char length = sizeof(suffix) / sizeof(suffix[0]);

		int i = 0;
		double dblBytes = bytes;

		if (bytes > 1024) {
			for (i = 0; (bytes / 1024) > 0 && i < length - 1; i++, bytes /= 1024)
				dblBytes = bytes / 1024.0;
		}

		static char output[0x8000];
		std::snprintf(output, sizeof(output), "%.02lf %s", dblBytes, suffix[i]);
		return std::string(output);
	}
}