file.carbon 824 B

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