| 845 | |
| 846 | #ifdef EXV_ENABLE_FILESYSTEM |
| 847 | Image::UniquePtr ImageFactory::create(ImageType type, const std::string& path) { |
| 848 | auto fileIo = std::make_unique<FileIo>(path); |
| 849 | // Create or overwrite the file, then close it |
| 850 | if (fileIo->open("w+b") != 0) { |
| 851 | throw Error(ErrorCode::kerFileOpenFailed, path, "w+b", strError()); |
| 852 | } |
| 853 | fileIo->close(); |
| 854 | |
| 855 | BasicIo::UniquePtr io(std::move(fileIo)); |
| 856 | auto image = create(type, std::move(io)); |
| 857 | if (!image) |
| 858 | throw Error(ErrorCode::kerUnsupportedImageType, static_cast<int>(type)); |
| 859 | return image; |
| 860 | } |
| 861 | #endif |
| 862 | |
| 863 | Image::UniquePtr ImageFactory::create(ImageType type) { |