diff options
Diffstat (limited to 'src/components/utils/src/file_system.cc')
-rw-r--r-- | src/components/utils/src/file_system.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/components/utils/src/file_system.cc b/src/components/utils/src/file_system.cc index f98aeda056..430cf40da0 100644 --- a/src/components/utils/src/file_system.cc +++ b/src/components/utils/src/file_system.cc @@ -316,6 +316,26 @@ bool file_system::ReadBinaryFile(const std::string& name, return true; } +bool file_system::ReadBinaryFile(const std::string& name, + std::vector<uint8_t>& result, + uint32_t offset, + uint32_t length) { + if (!FileExists(name) || !IsAccessible(name, R_OK)) { + return false; + } + + std::ifstream file(name.c_str(), std::ios_base::binary); + file.ignore(offset); + std::ostringstream ss; + std::string s; + s.resize(length); + file.read(&s[0], length); + + result.resize(s.length()); + std::copy(s.begin(), s.end(), result.begin()); + return true; +} + bool file_system::ReadFile(const std::string& name, std::string& result) { if (!FileExists(name) || !IsAccessible(name, R_OK)) { return false; |