| Index: src/DefaultFileSystem.cpp |
| =================================================================== |
| --- a/src/DefaultFileSystem.cpp |
| +++ b/src/DefaultFileSystem.cpp |
| @@ -61,30 +61,39 @@ |
| // file paths as they are. |
| std::string NormalizePath(const std::string& path) |
| { |
| return path; |
| } |
| #endif |
| } |
| -std::shared_ptr<std::istream> |
| +FileSystem::IOBuffer |
| DefaultFileSystem::Read(const std::string& path) const |
| { |
| - std::shared_ptr<std::istream> result(new std::ifstream(NormalizePath(path).c_str())); |
| - if (result->fail()) |
| + std::ifstream file(NormalizePath(path).c_str(), std::ios_base::binary); |
| + if (file.fail()) |
| throw RuntimeErrorWithErrno("Failed to open " + path); |
| - return result; |
| + |
| + file.seekg(0, std::ios_base::end); |
| + auto dataSize = file.tellg(); |
| + file.seekg(0, std::ios_base::beg); |
| + |
| + IOBuffer data(dataSize); |
| + file.read(reinterpret_cast<std::ifstream::char_type*>(data.data()), |
| + data.size()); |
| + return data; |
| } |
| void DefaultFileSystem::Write(const std::string& path, |
| - std::istream& data) |
| + const IOBuffer& data) |
| { |
| std::ofstream file(NormalizePath(path).c_str(), std::ios_base::out | std::ios_base::binary); |
| - file << Utils::Slurp(data); |
| + file.write(reinterpret_cast<const std::ofstream::char_type*>(data.data()), |
| + data.size()); |
| } |
| void DefaultFileSystem::Move(const std::string& fromPath, |
| const std::string& toPath) |
| { |
| if (rename(NormalizePath(fromPath).c_str(), NormalizePath(toPath).c_str())) |
| throw RuntimeErrorWithErrno("Failed to move " + fromPath + " to " + toPath); |
| } |