MCPcopy Create free account
hub / github.com/Tencent/tgfx / MakeFromFile

Method MakeFromFile

src/core/utils/Stream.cpp:123–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121}
122
123std::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
153std::unique_ptr<Stream> Stream::MakeFromData(std::shared_ptr<Data> data) {
154 if (data == nullptr) {

Callers

nothing calls this directly

Calls 4

GetProtocolFromPathFunction · 0.85
unlockMethod · 0.80
c_strMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected