-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileManager.cpp
More file actions
35 lines (28 loc) · 836 Bytes
/
Copy pathfileManager.cpp
File metadata and controls
35 lines (28 loc) · 836 Bytes
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
35
#include "fileManager.h"
auto FileManager::IsExist(std::string filePath) -> bool
{
std::ifstream file(filePath);
return file.good();
}
auto FileManager::ReadBuffer(std::string filePath) -> std::vector<std::uint8_t>
{
std::vector<std::uint8_t> buffer;
std::ifstream file(filePath, std::ios::binary);
if (!file)
return buffer;
file.seekg(0, std::ios::end);
auto fileSize = file.tellg();
file.seekg(0, std::ios::beg);
buffer.resize(fileSize);
file.read(reinterpret_cast<char*>(buffer.data()), fileSize);
file.close();
return buffer;
}
void FileManager::WriteBuffer(std::string filePath, std::vector<std::uint8_t> buffer)
{
std::ofstream file(filePath, std::ios::binary);
if (!file)
return;
file.write(reinterpret_cast<const char*>(buffer.data()), buffer.size());
file.close();
}