MCPcopy Create free account
hub / github.com/bytedance/Fastbot_Android / LoadFileRaw

Function LoadFileRaw

native/thirdpart/flatbuffers/util.cpp:58–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58bool LoadFileRaw(const char *name, bool binary, std::string *buf) {
59 if (DirExists(name)) return false;
60 std::ifstream ifs(name, binary ? std::ifstream::binary : std::ifstream::in);
61 if (!ifs.is_open()) return false;
62 if (binary) {
63 // The fastest way to read a file into a string.
64 ifs.seekg(0, std::ios::end);
65 auto size = ifs.tellg();
66 (*buf).resize(static_cast<size_t>(size));
67 ifs.seekg(0, std::ios::beg);
68 ifs.read(&(*buf)[0], (*buf).size());
69 } else {
70 // This is slower, but works correctly on all platforms for text files.
71 std::ostringstream oss;
72 oss << ifs.rdbuf();
73 *buf = oss.str();
74 }
75 return !ifs.bad();
76}
77
78static LoadFileFunction g_load_file_function = LoadFileRaw;
79static FileExistsFunction g_file_exists_function = FileExistsRaw;

Callers

nothing calls this directly

Calls 4

DirExistsFunction · 0.85
readMethod · 0.45
sizeMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected