1 // Copyright (c) 2015-2021 The Limenka developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 5 #ifndef LIMENKA_UTIL_READWRITEFILE_H
6 #define LIMENKA_UTIL_READWRITEFILE_H
7 8 #include <util/fs.h>
9 10 #include <limits>
11 #include <string>
12 #include <utility>
13 14 /** Read full contents of a file and return them in a std::string.
15 * Returns a pair <status, string>.
16 * If an error occurred, status will be false, otherwise status will be true and the data will be returned in string.
17 *
18 * @param maxsize Puts a maximum size limit on the file that is read. If the file is larger than this, truncated data
19 * (with len > maxsize) will be returned.
20 */
21 std::pair<bool,std::string> ReadBinaryFile(const fs::path &filename, size_t maxsize=std::numeric_limits<size_t>::max());
22 23 /** Write contents of std::string to a file.
24 * @return true on success.
25 */
26 bool WriteBinaryFile(const fs::path &filename, const std::string &data);
27 28 #endif // LIMENKA_UTIL_READWRITEFILE_H
29