1 // Copyright 2016 The Chromium Embedded Framework Authors. Portions copyright 2 // 2012 The Chromium Authors. All rights reserved. Use of this source code is 3 // governed by a BSD-style license that can be found in the LICENSE file. 4 5 #ifndef CEF_TESTS_SHARED_BROWSER_FILE_UTIL_H_ 6 #define CEF_TESTS_SHARED_BROWSER_FILE_UTIL_H_ 7 #pragma once 8 9 #include <limits> 10 #include <string> 11 12 namespace client { 13 namespace file_util { 14 15 // Platform-specific path separator. 16 extern const char kPathSep; 17 18 // Reads the file at |path| into |contents| and returns true on success and 19 // false on error. In case of I/O error, |contents| holds the data that could 20 // be read from the file before the error occurred. When the file size exceeds 21 // max_size|, the function returns false with |contents| holding the file 22 // truncated to |max_size|. |contents| may be nullptr, in which case this 23 // function is useful for its side effect of priming the disk cache (could be 24 // used for unit tests). Calling this function on the browser process UI or IO 25 // threads is not allowed. 26 bool ReadFileToString(const std::string& path, 27 std::string* contents, 28 size_t max_size = std::numeric_limits<size_t>::max()); 29 30 // Writes the given buffer into the file, overwriting any data that was 31 // previously there. Returns the number of bytes written, or -1 on error. 32 // Calling this function on the browser process UI or IO threads is not allowed. 33 int WriteFile(const std::string& path, const char* data, int size); 34 35 // Combines |path1| and |path2| with the correct platform-specific path 36 // separator. 37 std::string JoinPath(const std::string& path1, const std::string& path2); 38 39 // Extracts the file extension from |path|. 40 std::string GetFileExtension(const std::string& path); 41 42 } // namespace file_util 43 } // namespace client 44 45 #endif // CEF_TESTS_SHARED_BROWSER_FILE_UTIL_H_ 46