7 #include "packager/media/file/local_file.h"
11 #include "packager/base/files/file_util.h"
12 #include "packager/base/logging.h"
18 :
File(file_name), file_mode_(mode), internal_file_(NULL) {}
23 result = base::CloseFile(internal_file_);
24 internal_file_ = NULL;
31 DCHECK(buffer != NULL);
32 DCHECK(internal_file_ != NULL);
33 return fread(buffer,
sizeof(
char), length, internal_file_);
37 DCHECK(buffer != NULL);
38 DCHECK(internal_file_ != NULL);
39 return fwrite(buffer,
sizeof(
char), length, internal_file_);
43 DCHECK(internal_file_ != NULL);
47 LOG(ERROR) <<
"Cannot flush file.";
52 if (!base::GetFileSize(base::FilePath(
file_name()), &file_size)) {
53 LOG(ERROR) <<
"Cannot get file size.";
60 DCHECK(internal_file_ != NULL);
61 return ((fflush(internal_file_) == 0) && !ferror(internal_file_));
65 return fseeko(internal_file_, position, SEEK_SET) >= 0;
69 off_t offset = ftello(internal_file_);
76 LocalFile::~LocalFile() {}
80 base::OpenFile(base::FilePath(
file_name()), file_mode_.c_str());
81 return (internal_file_ != NULL);
85 return base::DeleteFile(base::FilePath(file_name),
false);