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:
sdong 2020-02-04 11:37:07 -08:00 committed by Facebook Github Bot
parent 69c8614815
commit 3a073234da

24
env/env.cc vendored
View File

@ -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) {
EnvOptions soptions;
data->clear();
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;
LegacyFileSystemWrapper lfsw(env);
return ReadFileToString(&lfsw, fname, data);
}
EnvWrapper::~EnvWrapper() {