| 1 | // LAF Base Library |
| 2 | // Copyright (C) 2018-2022 Igara Studio S.A. |
| 3 | // |
| 4 | // This file is released under the terms of the MIT license. |
| 5 | // Read LICENSE.txt for more information. |
| 6 | |
| 7 | #ifndef BASE_FILE_CONTENT_H_INCLUDED |
| 8 | #define BASE_FILE_CONTENT_H_INCLUDED |
| 9 | #pragma once |
| 10 | |
| 11 | #include "base/buffer.h" |
| 12 | |
| 13 | #include <cstdio> |
| 14 | #include <string> |
| 15 | |
| 16 | namespace base { |
| 17 | |
| 18 | buffer read_file_content(FILE* file); |
| 19 | buffer read_file_content(const std::string& filename); |
| 20 | |
| 21 | void write_file_content(FILE* file, const uint8_t* data, size_t size); |
| 22 | void write_file_content(const std::string& filename, const uint8_t* data, size_t size); |
| 23 | |
| 24 | inline void write_file_content(FILE* file, const buffer& buf) { |
| 25 | if (!buf.empty()) |
| 26 | write_file_content(file, &buf[0], buf.size()); |
| 27 | } |
| 28 | |
| 29 | inline void write_file_content(const std::string& filename, const buffer& buf) { |
| 30 | if (!buf.empty()) |
| 31 | write_file_content(filename, &buf[0], buf.size()); |
| 32 | } |
| 33 | |
| 34 | // Can be used on Windows to write binary content to stdout or other |
| 35 | // FILE handles. |
| 36 | void set_write_binary_file_content(FILE* file); |
| 37 | |
| 38 | } // namespace base |
| 39 | |
| 40 | #endif |
| 41 | |