-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIOManager.cpp
More file actions
57 lines (45 loc) · 1.09 KB
/
Copy pathIOManager.cpp
File metadata and controls
57 lines (45 loc) · 1.09 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "IOManager.h"
#include <fstream>
namespace KlaoudeEngine
{
bool IOManager::readFileToBuffer(std::string filePath, std::vector<unsigned char>& buffer)
{
std::ifstream file(filePath, std::ios::binary);
if (file.fail())
{
perror(filePath.c_str());
return false;
}
//seek to the end
file.seekg(0, std::ios::end);
//Get file size
int fileSize = file.tellg();
file.seekg(0, std::ios::beg);
//Reduce file size by any header bytes
fileSize -= file.tellg();
buffer.resize(fileSize);
file.read((char *)&(buffer[0]), fileSize);
file.close();
return true;
}
bool IOManager::readFileToBuffer(std::string filePath, std::string & buffer)
{
std::ifstream file(filePath, std::ios::binary);
if (file.fail())
{
perror(filePath.c_str());
return false;
}
//seek to the end
file.seekg(0, std::ios::end);
//Get file size
int fileSize = file.tellg();
file.seekg(0, std::ios::beg);
//Reduce file size by any header bytes
fileSize -= file.tellg();
buffer.resize(fileSize);
file.read((char *)&(buffer[0]), fileSize);
file.close();
return true;
}
}