-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathFile.hpp
39 lines (34 loc) · 969 Bytes
/
File.hpp
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
#include <fstream>
#include <string>
namespace File {
bool Contain(const char* path, const char* dest) {
std::ifstream infile(path, std::ios::in | std::ios::binary | std::ios::ate);
size_t size = infile.tellg();
infile.seekg(0, std::ios::beg);
char* buffer = new char[size];
infile.read(buffer, size);
infile.close();
std::string alltext(buffer, size);
delete[] buffer;
return alltext.find(dest) != std::string::npos;
}
char* ReadBytes(const char* path) {
std::ifstream infile(path, std::ios::in | std::ios::binary | std::ios::ate);
size_t size = infile.tellg();
infile.seekg(0, std::ios::beg);
char* buffer = new char[size];
infile.read(buffer, size);
infile.close();
return buffer;
}
std::string Extract(const char* path, size_t offset, size_t length) {
char* buffer = ReadBytes(path);
if (buffer) {
std::string a(buffer + offset, length);
delete[] buffer;
return a;
}
delete[] buffer;
return nullptr;
}
}