MCPcopy Create free account
hub / github.com/dmlc/xgboost / LoadSequentialFile

Function LoadSequentialFile

src/common/io.cc:139–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137} // anonymous namespace
138
139std::vector<char> LoadSequentialFile(std::string uri) {
140 auto OpenErr = [&uri]() {
141 std::string msg;
142 msg = "Opening " + uri + " failed: ";
143 msg += error::SystemError().message();
144 LOG(FATAL) << msg;
145 };
146
147 auto parsed = dmlc::io::URI(uri.c_str());
148 CHECK((parsed.protocol == "file://" || parsed.protocol.length() == 0))
149 << "Only local file is supported.";
150 // Read from file.
151 auto path = std::filesystem::weakly_canonical(std::filesystem::u8path(uri));
152 std::ifstream ifs(path, std::ios_base::binary | std::ios_base::in);
153 if (!ifs) {
154 // https://stackoverflow.com/a/17338934
155 OpenErr();
156 }
157
158 auto file_size = std::filesystem::file_size(path);
159 std::vector<char> buffer(file_size);
160 ifs.read(&buffer[0], file_size);
161
162 return buffer;
163}
164
165std::string FileExtension(std::string fname, bool lower) {
166 if (lower) {

Callers 6

XGBoosterLoadModelFunction · 0.85
TESTFunction · 0.85
TESTFunction · 0.85
TESTFunction · 0.85
TESTFunction · 0.85

Calls 3

SystemErrorFunction · 0.85
c_strMethod · 0.80
readMethod · 0.45

Tested by 5

TESTFunction · 0.68
TESTFunction · 0.68
TESTFunction · 0.68
TESTFunction · 0.68