#include "dps/fs_utils.hpp"

#include <fstream>
#include <iterator>
#include <sstream>

namespace fs = std::filesystem;

namespace dps {

fs::path path_from_utf8(const std::string &value) {
    return fs::u8path(value);
}

std::string path_to_utf8_string(const fs::path &path) {
    return path.u8string();
}

std::string read_text_file(const fs::path &path) {
    std::ifstream input(path, std::ios::binary);
    if (!input.good()) return "";
    std::ostringstream buffer;
    buffer << input.rdbuf();
    return buffer.str();
}

std::vector<unsigned char> read_binary_file(const fs::path &path) {
    std::ifstream input(path, std::ios::binary);
    if (!input.good()) return {};
    return std::vector<unsigned char>((std::istreambuf_iterator<char>(input)), std::istreambuf_iterator<char>());
}

}  // namespace dps
