@geastack/host 0.1.24 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/host/image.cpp +11 -2
- package/package.json +1 -1
package/host/image.cpp
CHANGED
|
@@ -55,11 +55,20 @@ namespace gea::platform::storage {
|
|
|
55
55
|
namespace {
|
|
56
56
|
bool (*g_mount_provider)() = nullptr;
|
|
57
57
|
bool (*g_fallback_mount_provider)() = nullptr;
|
|
58
|
+
std::string (*g_read_path_provider)(const std::string &) = nullptr;
|
|
58
59
|
} // namespace
|
|
59
60
|
void setMountProvider(bool (*provider)()) { g_mount_provider = provider; }
|
|
60
61
|
void setFallbackMountProvider(bool (*provider)()) {
|
|
61
62
|
g_fallback_mount_provider = provider;
|
|
62
63
|
}
|
|
64
|
+
void setReadPathProvider(std::string (*provider)(const std::string &)) {
|
|
65
|
+
g_read_path_provider = provider;
|
|
66
|
+
}
|
|
67
|
+
static std::FILE *openRead(const std::string &path) {
|
|
68
|
+
if (g_read_path_provider)
|
|
69
|
+
return std::fopen(g_read_path_provider(path).c_str(), "rb");
|
|
70
|
+
return std::fopen(path.c_str(), "rb");
|
|
71
|
+
}
|
|
63
72
|
bool ensureMounted() {
|
|
64
73
|
auto provider =
|
|
65
74
|
g_mount_provider ? g_mount_provider : g_fallback_mount_provider;
|
|
@@ -164,7 +173,7 @@ void mapReadTask(void *arg) {
|
|
|
164
173
|
|
|
165
174
|
std::vector<std::uint8_t> readWholeFile(const std::string &path) {
|
|
166
175
|
std::vector<std::uint8_t> out;
|
|
167
|
-
std::FILE *f =
|
|
176
|
+
std::FILE *f = gea::platform::storage::openRead(path);
|
|
168
177
|
if (!f)
|
|
169
178
|
return out;
|
|
170
179
|
std::fseek(f, 0, SEEK_END);
|
|
@@ -298,7 +307,7 @@ std::vector<std::uint8_t> ImageService::readFileRange(const std::string &path,
|
|
|
298
307
|
if (path.empty() || offset < 0 || length <= 0 ||
|
|
299
308
|
!gea::platform::storage::ensureMounted())
|
|
300
309
|
return;
|
|
301
|
-
std::FILE *f =
|
|
310
|
+
std::FILE *f = gea::platform::storage::openRead(path);
|
|
302
311
|
if (!f)
|
|
303
312
|
return;
|
|
304
313
|
if (std::fseek(f, static_cast<long>(offset), SEEK_SET) == 0) {
|