| 227 | } |
| 228 | |
| 229 | std::string ZipFile::getFileDataAsString(const std::string& filename) { |
| 230 | std::string buffer; |
| 231 | BLOCK_START { |
| 232 | BREAK_IF(!_file); |
| 233 | BREAK_IF(filename.empty()); |
| 234 | std::string searchName = getSearchName(filename); |
| 235 | auto it = _file->fileList.find(searchName); |
| 236 | BREAK_IF(it == _file->fileList.end()); |
| 237 | auto archive = &_file->archive; |
| 238 | size_t bufSize = s_cast<size_t>(it->second.size); |
| 239 | buffer.resize(bufSize); |
| 240 | if (!mz_zip_reader_extract_file_to_mem(archive, it->second.name.c_str(), buffer.data(), bufSize, 0)) { |
| 241 | auto err = mz_zip_get_error_string(mz_zip_get_last_error(archive)); |
| 242 | Error("failed to extract file \"{}\" from zip: {}.", it->second.name, err); |
| 243 | } |
| 244 | } |
| 245 | BLOCK_END |
| 246 | return buffer; |
| 247 | } |
no test coverage detected