Debian Codegraph @

src/file.h

raw
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 using std::string;
18
19
20 inline string GetFileContent(string filename) {
21 std::ifstream ifs(filename.c_str(), std::ios::binary);
22 return string(
23 std::istreambuf_iterator<char>(ifs.rdbuf()),
24 std::istreambuf_iterator<char>());
25 }
26
27 inline void SetFileContents(string filename, string::iterator start,
28 string::iterator end) {
29 std::ofstream ofs(filename.c_str(), std::ios::binary);
30 std::copy(start, end, std::ostream_iterator<char>(ofs));
31 }
32
33 } // namespace woff2
34 #endif // WOFF2_FILE_H_