| 71 | } |
| 72 | |
| 73 | Status DoReadFileToString(Env* env, const std::string& fname, faststring* data, bool is_sensitive) { |
| 74 | data->clear(); |
| 75 | unique_ptr<SequentialFile> file; |
| 76 | SequentialFileOptions opts; |
| 77 | opts.is_sensitive = is_sensitive; |
| 78 | Status s = env->NewSequentialFile(opts, fname, &file); |
| 79 | if (!s.ok()) { |
| 80 | return s; |
| 81 | } |
| 82 | static const int kBufferSize = 8192; |
| 83 | unique_ptr<uint8_t[]> scratch(new uint8_t[kBufferSize]); |
| 84 | while (true) { |
| 85 | Slice fragment(scratch.get(), kBufferSize); |
| 86 | s = file->Read(&fragment); |
| 87 | if (!s.ok()) { |
| 88 | break; |
| 89 | } |
| 90 | data->append(fragment.data(), fragment.size()); |
| 91 | if (fragment.empty()) { |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | return s; |
| 96 | } |
| 97 | |
| 98 | Status ReadFileToString(Env* env, const std::string& fname, faststring* data) { |
| 99 | return DoReadFileToString(env, fname, data, false); |