7 #include "packager/media/file/local_file.h"
12 #endif // defined(OS_WIN)
13 #include "packager/base/files/file_util.h"
14 #include "packager/base/logging.h"
20 const char kAdditionalFileMode[] =
"b";
25 internal_file_(NULL) {
26 if (file_mode_.find(kAdditionalFileMode) == std::string::npos)
27 file_mode_ += kAdditionalFileMode;
33 result = base::CloseFile(internal_file_);
34 internal_file_ = NULL;
41 DCHECK(buffer != NULL);
42 DCHECK(internal_file_ != NULL);
43 return fread(buffer,
sizeof(
char), length, internal_file_);
47 DCHECK(buffer != NULL);
48 DCHECK(internal_file_ != NULL);
49 return fwrite(buffer,
sizeof(
char), length, internal_file_);
53 DCHECK(internal_file_ != NULL);
57 LOG(ERROR) <<
"Cannot flush file.";
62 if (!base::GetFileSize(base::FilePath::FromUTF8Unsafe(
file_name()),
64 LOG(ERROR) <<
"Cannot get file size.";
71 DCHECK(internal_file_ != NULL);
72 return ((fflush(internal_file_) == 0) && !ferror(internal_file_));
77 return _fseeki64(internal_file_, static_cast<__int64>(position),
80 return fseeko(internal_file_, position, SEEK_SET) >= 0;
81 #endif // !defined(OS_WIN)
86 __int64 offset = _ftelli64(internal_file_);
88 off_t offset = ftello(internal_file_);
89 #endif // !defined(OS_WIN)
92 *position =
static_cast<uint64_t
>(offset);
96 LocalFile::~LocalFile() {}
100 base::OpenFile(base::FilePath::FromUTF8Unsafe(
file_name()), file_mode_.c_str());
101 return (internal_file_ != NULL);
105 return base::DeleteFile(base::FilePath::FromUTF8Unsafe(file_name),
false);