| 1728 | // free functions |
| 1729 | #ifdef EXV_ENABLE_FILESYSTEM |
| 1730 | DataBuf readFile(const std::string& path) { |
| 1731 | FileIo file(path); |
| 1732 | if (file.open("rb") != 0) { |
| 1733 | throw Error(ErrorCode::kerFileOpenFailed, path, "rb", strError()); |
| 1734 | } |
| 1735 | struct stat st; |
| 1736 | if (0 != ::stat(path.c_str(), &st)) { |
| 1737 | throw Error(ErrorCode::kerCallFailed, path, strError(), "::stat"); |
| 1738 | } |
| 1739 | DataBuf buf(st.st_size); |
| 1740 | if (file.read(buf.data(), buf.size()) != buf.size()) { |
| 1741 | throw Error(ErrorCode::kerCallFailed, path, strError(), "FileIo::read"); |
| 1742 | } |
| 1743 | return buf; |
| 1744 | } |
| 1745 | |
| 1746 | size_t writeFile(const DataBuf& buf, const std::string& path) { |
| 1747 | FileIo file(path); |