Don't re-open WebVTT file to determine size.

Change-Id: Id92226adce813b7d0c4c741e47e36dbf8f208797
This commit is contained in:
Jacob Trimble 2021-02-04 14:02:33 -08:00
parent 36ef7ec945
commit 95089593fc
3 changed files with 5 additions and 6 deletions

View File

@ -73,10 +73,12 @@ void WebVttFileBuffer::Append(const TextSample& sample) {
buffer_.append("\n"); // end of sample
}
bool WebVttFileBuffer::WriteTo(File* file) {
bool WebVttFileBuffer::WriteTo(File* file, uint64_t* size) {
DCHECK(file);
DCHECK_GT(buffer_.size(), 0u) << "The buffer should at least have a header";
if (size)
*size = buffer_.size();
const int written = file->Write(buffer_.c_str(), buffer_.size());
if (written < 0) {
return false;

View File

@ -27,7 +27,7 @@ class WebVttFileBuffer {
void Reset();
void Append(const TextSample& sample);
bool WriteTo(File* file);
bool WriteTo(File* file, uint64_t* size);
// Get the number of samples that have been appended to this file.
size_t sample_count() const { return sample_count_; }

View File

@ -45,15 +45,12 @@ Status WebVttMuxer::WriteToFile(const std::string& filename, uint64_t* size) {
return Status(error::FILE_FAILURE, "Failed to open " + filename);
}
buffer_->WriteTo(file.get());
buffer_->WriteTo(file.get(), size);
buffer_->Reset();
if (!file.release()->Close()) {
return Status(error::FILE_FAILURE, "Failed to close " + filename);
}
if (size) {
*size = File::GetFileSize(filename.c_str());
}
return Status::OK;
}