MCPcopy Create free account
hub / github.com/LagPixelLOL/ChatGPTCLIBot / write_binary_file

Function write_binary_file

main/interface/util/FileUtils.cpp:135–151  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

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.

Callers 1

downloadFunction · 0.85

Calls 3

file_errorClass · 0.85
sizeMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected