Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
FileHanlder.cpp
Go to the documentation of this file.
1#include <string>
2
4#include <vector>
5#include <iostream>
6#include <fstream>
7#include <plog/Log.h>
8
9std::vector<char> FileHandler::readFile(const std::string &filename) {
10 PLOGI << "Reading file: " << filename;
11
12
13 // ate means at the end and binary means read it as binary to avoid conversion
14 std::ifstream file(filename, std::ios::ate | std::ios::binary);
15
16 if (!file.is_open()) {
17 std::stringstream ss;
18 ss << "Failed to open file: " << filename;
19 throw std::runtime_error(ss.str());
20 }
21
22 // starting at the end of the file give me a character count which is now the size of the buffer
23 size_t fileSize = file.tellg();
24 std::vector<char> buffer(fileSize);
25
26 PLOGI << "File size: " << fileSize;
27
28 // go back to the beginning and read the file
29 file.seekg(0);
30 file.read(buffer.data(), fileSize);
31
32 file.close();
33 PLOGI << "File read successfully!";
34 return buffer;
35}
36
37std::ifstream FileHandler::readFileAsStream(const std::filesystem::path &path) {
38 std::ifstream file(path);
39 return file;
40}
41
42
static std::ifstream readFileAsStream(const std::filesystem::path &path)
static std::vector< char > readFile(const std::string &filename)