wren
Vulkan-based game engine
Loading...
Searching...
No Matches
filesystem.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <filesystem>
4#include <fstream>
5#include <vector>
6
7namespace wren::utils::fs {
8
9auto read_file_to_string(const std::filesystem::path& path) {
10 std::ifstream file(path);
11 std::string result;
12 file >> result;
13 return result;
14}
15
16auto read_file_to_bin(const std::filesystem::path& path) {
17 std::ifstream file(path, std::ios::binary);
18
19 std::streampos size;
20 file.seekg(0, std::ios::end);
21 size = file.tellg();
22 file.seekg(0, std::ios::beg);
23
24 std::vector<uint8_t> buf;
25 buf.reserve(size);
26
27 buf.insert(buf.begin(), std::istreambuf_iterator<char>(file),
28 std::istreambuf_iterator<char>());
29
30 return buf;
31}
32
33} // namespace wren::utils::fs
Definition filesystem.hpp:7
auto read_file_to_string(const std::filesystem::path &path)
Definition filesystem.hpp:9
auto read_file_to_bin(const std::filesystem::path &path)
Definition filesystem.hpp:16