-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathfile_utils.hpp
More file actions
39 lines (30 loc) · 843 Bytes
/
file_utils.hpp
File metadata and controls
39 lines (30 loc) · 843 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
36
37
38
39
#ifndef FILE_UTILS_HPP
#define FILE_UTILS_HPP
#include <vector>
#include <fstream>
using namespace std;
namespace api2captcha
{
class FileUtils
{
public:
static const vector<unsigned char> readFile(std::string &file_path)
{
// 1. Read the image file into a byte vector
ifstream file(file_path, ios::binary | ios::ate);
if (file.is_open())
{
streamsize size = file.tellg();
file.seekg(0, ios::beg);
vector<unsigned char> file_data(size);
if (file.read(reinterpret_cast<char *>(file_data.data()), size))
{
file.close();
return file_data;
}
}
return {};
}
};
};
#endif /* FILE_UTILS_HPP */