| 121 | } |
| 122 | |
| 123 | std::unique_ptr<Stream> Stream::MakeFromFile(const std::string& filePath) { |
| 124 | if (filePath.empty()) { |
| 125 | return nullptr; |
| 126 | } |
| 127 | auto protocol = GetProtocolFromPath(filePath); |
| 128 | if (!protocol.empty()) { |
| 129 | locker.lock(); |
| 130 | auto streamFactory = customProtocolsMap[protocol]; |
| 131 | locker.unlock(); |
| 132 | if (streamFactory) { |
| 133 | auto stream = streamFactory->createStream(filePath); |
| 134 | if (stream) { |
| 135 | return stream; |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | auto file = fopen(filePath.c_str(), "rb"); |
| 140 | if (file == nullptr) { |
| 141 | return nullptr; |
| 142 | } |
| 143 | fseek(file, 0, SEEK_END); |
| 144 | auto length = ftell(file); |
| 145 | if (length <= 0) { |
| 146 | fclose(file); |
| 147 | return nullptr; |
| 148 | } |
| 149 | fseek(file, 0, SEEK_SET); |
| 150 | return std::make_unique<FileStream>(file, length); |
| 151 | } |
| 152 | |
| 153 | std::unique_ptr<Stream> Stream::MakeFromData(std::shared_ptr<Data> data) { |
| 154 | if (data == nullptr) { |
nothing calls this directly
no test coverage detected