Load a file into a buffer
| 186 | |
| 187 | /// Load a file into a buffer |
| 188 | bool load_file(const std::string filename, std::vector<char>& buf, bool append) |
| 189 | { |
| 190 | std::ifstream file(filename, std::ios::binary); |
| 191 | if (!file.good()) { |
| 192 | LBANN_ERROR("!file.good() for filename: ", filename); |
| 193 | } |
| 194 | |
| 195 | file.unsetf(std::ios::skipws); |
| 196 | |
| 197 | file.seekg(0, std::ios::end); |
| 198 | const std::streamsize file_size = static_cast<std::streamsize>(file.tellg()); |
| 199 | |
| 200 | file.seekg(0, std::ios::beg); |
| 201 | |
| 202 | if (!append) { |
| 203 | buf.clear(); |
| 204 | } |
| 205 | const size_t cur_size = buf.size(); |
| 206 | buf.resize(static_cast<size_t>(file_size) + cur_size); |
| 207 | |
| 208 | file.read(buf.data() + cur_size, file_size); |
| 209 | |
| 210 | return true; |
| 211 | } |
| 212 | |
| 213 | namespace file { |
| 214 |
no test coverage detected