-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile.cpp
More file actions
47 lines (40 loc) · 1.06 KB
/
File.cpp
File metadata and controls
47 lines (40 loc) · 1.06 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
#include "File.h"
bool fileExists(const std::string& filepath)
{
std::ifstream infile(filepath);
return infile.good();
}
std::vector<byte> ReadFileDataRaw(std::string filepath)
{
std::ifstream readStream(filepath, std::ios::in | std::ios::binary);
std::vector<byte> buffer = std::vector<byte>(std::istreambuf_iterator<byte>(readStream),std::istreambuf_iterator<byte>());
readStream.close();
return buffer;
}
void WriteFileDataRaw(std::string filepath, const std::vector<byte>& buffer)
{
std::ofstream writeStream(filepath, std::ios::out | std::ios::binary);
writeStream.write(&buffer[0], buffer.size());
writeStream.close();
}
bool CompareFiles(std::string filepath1, std::string filepath2)
{
auto buffer1 = ReadFileDataRaw(filepath1);
auto buffer2 = ReadFileDataRaw(filepath2);
if(buffer1.size() != buffer2.size()) return false;
for(size_t i = 0; i < buffer1.size(); i++)
{
if(buffer1[i] != buffer2[i]) return false;
}
return true;
}
/*
-128 > -127
-1 > 0
0 > -1
1 > 0
-1 > 0
0 > 1
0 > 1
-127 > -128
*/