1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <fstream>
#include <iostream>
#include <list>
#include <string>
#include "kmx_file.h"
#include "path.hpp"
#include "utfcodec.hpp"
namespace km::tests {
std::vector<uint8_t> load_kmx_file(km::core::path const& kb_path) {
std::vector<uint8_t> data;
std::ifstream file(static_cast<std::string>(kb_path), std::ios::binary | std::ios::ate);
if (file.fail()) {
return std::vector<uint8_t>();
}
const std::streamsize size = file.tellg();
if (size >= KMX_MAX_ALLOWED_FILE_SIZE) {
return std::vector<uint8_t>();
}
file.seekg(0, std::ios::beg);
data.resize((size_t)size);
if (!file.read((char*)data.data(), size)) {
return std::vector<uint8_t>();
}
file.close();
return data;
}
}
|