| 399 | } // namespace |
| 400 | |
| 401 | BundleWriter::BundleWriter(Env* env, StringPiece prefix, const Options& options) |
| 402 | : env_(env), |
| 403 | options_(options), |
| 404 | prefix_(prefix), |
| 405 | tmp_metadata_path_(strings::StrCat(MetaFilename(prefix_), ".tempstate", |
| 406 | random::New64())), |
| 407 | tmp_data_path_(strings::StrCat(DataFilename(prefix_, 0, 1), ".tempstate", |
| 408 | random::New64())), |
| 409 | out_(nullptr), |
| 410 | size_(0) { |
| 411 | status_ = env_->CreateDir(string(io::Dirname(prefix_))); |
| 412 | if (!status_.ok() && !errors::IsAlreadyExists(status_)) { |
| 413 | return; |
| 414 | } |
| 415 | const string filename = DataFilename(prefix_, 0, 1); |
| 416 | std::unique_ptr<WritableFile> wrapper; |
| 417 | status_ = env_->NewWritableFile(tmp_data_path_, &wrapper); |
| 418 | if (!status_.ok()) return; |
| 419 | out_ = std::unique_ptr<FileOutputBuffer>( |
| 420 | new FileOutputBuffer(wrapper.release(), 8 << 20 /* 8MB write buffer */)); |
| 421 | |
| 422 | VLOG(1) << "Writing to file " << tmp_data_path_; |
| 423 | } |
| 424 | |
| 425 | Status BundleWriter::Add(StringPiece key, const Tensor& val) { |
| 426 | if (!status_.ok()) return status_; |
nothing calls this directly
no test coverage detected