7 #ifndef PACKAGER_FILE_FILE_H_ 8 #define PACKAGER_FILE_FILE_H_ 14 #include "packager/base/macros.h" 15 #include "packager/file/public/buffer_callback_params.h" 19 extern const char* kCallbackFilePrefix;
20 extern const char* kLocalFilePrefix;
21 extern const char* kMemoryFilePrefix;
22 extern const char* kUdpFilePrefix;
23 const int64_t kWholeFile = -1;
47 static bool Delete(
const char* file_name);
54 virtual bool Close() = 0;
62 virtual int64_t
Read(
void* buffer, uint64_t length) = 0;
68 virtual int64_t
Write(
const void* buffer, uint64_t length) = 0;
72 virtual int64_t
Size() = 0;
79 virtual bool Flush() = 0;
84 virtual bool Seek(uint64_t position) = 0;
90 virtual bool Tell(uint64_t* position) = 0;
94 const std::string&
file_name()
const {
return file_name_; }
115 const std::string& contents);
122 const std::string& contents);
130 static bool Copy(
const char* from_file_name,
const char* to_file_name);
153 const std::string& name);
162 const std::string& callback_file_name,
167 explicit File(
const std::string& file_name) : file_name_(file_name) {}
173 virtual bool Open() = 0;
180 static File* Create(
const char* file_name,
const char* mode);
182 static File* CreateInternalFile(
const char* file_name,
const char* mode);
185 std::string file_name_;
187 DISALLOW_COPY_AND_ASSIGN(
File);
192 #endif // PACKAGER_FILE_FILE_H_ virtual int64_t Write(const void *buffer, uint64_t length)=0
static bool Delete(const char *file_name)
Define an abstract file interface.
static bool Copy(const char *from_file_name, const char *to_file_name)
static int64_t CopyFile(File *source, File *destination)
static bool ReadFileToString(const char *file_name, std::string *contents)
virtual int64_t Read(void *buffer, uint64_t length)=0
const std::string & file_name() const
Declaration of class which implements a thread-safe circular buffer.
All the methods that are virtual are virtual for mocking.
static int64_t GetFileSize(const char *file_name)
virtual bool Tell(uint64_t *position)=0
static bool WriteStringToFile(const char *file_name, const std::string &contents)
virtual bool Seek(uint64_t position)=0
static std::string MakeCallbackFileName(const BufferCallbackParams &callback_params, const std::string &name)
static File * OpenWithNoBuffering(const char *file_name, const char *mode)
static bool WriteFileAtomically(const char *file_name, const std::string &contents)
static bool ParseCallbackFileName(const std::string &callback_file_name, const BufferCallbackParams **callback_params, std::string *name)
virtual bool Open()=0
Internal open. Should not be used directly.