-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathFileUtils.h
More file actions
30 lines (25 loc) · 811 Bytes
/
FileUtils.h
File metadata and controls
30 lines (25 loc) · 811 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
#pragma once
#include <chrono>
#include <filesystem>
#include <fstream>
#include <string>
namespace rnexecutorch::fileutils {
inline std::string getTimeID() {
return std::to_string(std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count());
}
inline std::string loadBytesFromFile(const std::string &path) {
std::ifstream fs(path, std::ios::in | std::ios::binary);
if (fs.fail()) {
throw std::runtime_error("Failed to open tokenizer file");
}
std::string data;
fs.seekg(0, std::ios::end);
size_t size = static_cast<size_t>(fs.tellg());
fs.seekg(0, std::ios::beg);
data.resize(size);
fs.read(data.data(), size);
return data;
};
} // namespace rnexecutorch::fileutils