Skip to content

Commit

Permalink
Consolidate ReadFileToString() (facebook#6366)
Browse files Browse the repository at this point in the history
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: facebook#6366

Test Plan: Run all existing tests

Differential Revision: D19712332

fbshipit-source-id: 5ae6fabf6355938690d95cda52afd1f39e0a7823
  • Loading branch information
siying authored and facebook-github-bot committed Feb 4, 2020
1 parent 69c8614 commit 3a07323
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions env/env.cc
Expand Up @@ -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() {
Expand Down

0 comments on commit 3a07323

Please sign in to comment.