MCPcopy Create free account
hub / github.com/dmlc/parameter_server / readToString

Method readToString

src/util/file.cc:162–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160}
161
162int64 File::readToString(std::string* const output, uint64 max_length) {
163 CHECK_NOTNULL(output);
164 output->clear();
165
166 if (max_length == 0) return 0;
167 // if (max_length < 0) return -1;
168
169 int64 needed = max_length;
170 int bufsize = (needed < (2 << 20) ? needed : (2 << 20));
171
172 std::unique_ptr<char[]> buf(new char[bufsize]);
173
174 int64 nread = 0;
175 while (needed > 0) {
176 nread = read(buf.get(), (bufsize < needed ? bufsize : needed));
177 if (nread > 0) {
178 output->append(buf.get(), nread);
179 needed -= nread;
180 } else {
181 break;
182 }
183 }
184 return (nread >= 0 ? static_cast<int64>(output->size()) : -1);
185}
186
187size_t File::writeString(const std::string& line) {
188 return write(line.c_str(), line.size());

Callers 2

readFileToStringFunction · 0.80
readFileToProtoFunction · 0.80

Calls 4

appendMethod · 0.80
clearMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected