* Write binary data to a file. * @param content The data to write. * @param path Path to the file. * @throw file::file_error If the file cannot be opened or written. */
| 133 | * @throw file::file_error If the file cannot be opened or written. |
| 134 | */ |
| 135 | void write_binary_file(const std::vector<char>& content, const std::filesystem::path& path) { |
| 136 | try { |
| 137 | std::ofstream file(path.is_absolute() ? path : exe_parent_path / path, std::ios::binary); |
| 138 | if (!file.is_open() || file.bad()) { |
| 139 | throw file_error("File cannot be opened.", path); |
| 140 | } |
| 141 | file.write(content.data(), static_cast<std::streamsize>(content.size())); |
| 142 | if (file.bad()) { |
| 143 | throw file_error("File cannot be written.", path); |
| 144 | } |
| 145 | file.close(); |
| 146 | } catch (const file_error& e) { |
| 147 | throw; |
| 148 | } catch (const std::exception& e) { |
| 149 | throw file_error(e.what(), path); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Create a folder, including all parent folders. |
no test coverage detected