file.h (837B)
1 /* Copyright 2013 Google Inc. All Rights Reserved. 2 3 Distributed under MIT license. 4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT 5 */ 6 7 /* File IO helpers. */ 8 9 #ifndef WOFF2_FILE_H_ 10 #define WOFF2_FILE_H_ 11 12 #include <fstream> 13 #include <iterator> 14 15 namespace woff2 { 16 17 inline std::string GetFileContent(std::string filename) { 18 std::ifstream ifs(filename.c_str(), std::ios::binary); 19 return std::string(std::istreambuf_iterator<char>(ifs.rdbuf()), 20 std::istreambuf_iterator<char>()); 21 } 22 23 inline void SetFileContents(std::string filename, std::string::iterator start, 24 std::string::iterator end) { 25 std::ofstream ofs(filename.c_str(), std::ios::binary); 26 std::copy(start, end, std::ostream_iterator<char>(ofs)); 27 } 28 29 } // namespace woff2 30 #endif // WOFF2_FILE_H_