Consolidate ReadFileToString() (#6366)
Summary: It's a minor refactoring. We have two ReadFileToString() but they are very similar. Make the one with Env argument calls the one with FS argument instead. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6366 Test Plan: Run all existing tests Differential Revision: D19712332 fbshipit-source-id: 5ae6fabf6355938690d95cda52afd1f39e0a7823
This commit is contained in:
parent
69c8614815
commit
3a073234da
24
env/env.cc
vendored
24
env/env.cc
vendored
@ -378,28 +378,8 @@ Status WriteStringToFile(Env* env, const Slice& data, const std::string& fname,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Status ReadFileToString(Env* env, const std::string& fname, std::string* data) {
|
Status ReadFileToString(Env* env, const std::string& fname, std::string* data) {
|
||||||
EnvOptions soptions;
|
LegacyFileSystemWrapper lfsw(env);
|
||||||
data->clear();
|
return ReadFileToString(&lfsw, fname, data);
|
||||||
std::unique_ptr<SequentialFile> file;
|
|
||||||
Status s = env->NewSequentialFile(fname, &file, soptions);
|
|
||||||
if (!s.ok()) {
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
static const int kBufferSize = 8192;
|
|
||||||
char* space = new char[kBufferSize];
|
|
||||||
while (true) {
|
|
||||||
Slice fragment;
|
|
||||||
s = file->Read(kBufferSize, &fragment, space);
|
|
||||||
if (!s.ok()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
data->append(fragment.data(), fragment.size());
|
|
||||||
if (fragment.empty()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delete[] space;
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EnvWrapper::~EnvWrapper() {
|
EnvWrapper::~EnvWrapper() {
|
||||||
|
Loading…
Reference in New Issue
Block a user