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"
16 #include "packager/status.h"
20 extern const char* kCallbackFilePrefix;
21 extern const char* kLocalFilePrefix;
22 extern const char* kMemoryFilePrefix;
23 extern const char* kUdpFilePrefix;
24 extern const char* kHttpFilePrefix;
25 const int64_t kWholeFile = -1;
36 static File* Open(
const char* file_name,
const char* mode);
44 static File* OpenWithNoBuffering(
const char* file_name,
const char* mode);
49 static bool Delete(
const char* file_name);
56 virtual bool Close() = 0;
64 virtual int64_t Read(
void* buffer, uint64_t length) = 0;
70 virtual int64_t Write(
const void* buffer, uint64_t length) = 0;
74 virtual int64_t Size() = 0;
81 virtual bool Flush() = 0;
86 virtual bool Seek(uint64_t position) = 0;
92 virtual bool Tell(uint64_t* position) = 0;
96 const std::string&
file_name()
const {
return file_name_; }
104 static int64_t GetFileSize(
const char* file_name);
110 static bool ReadFileToString(
const char* file_name, std::string* contents);
116 static bool WriteStringToFile(
const char* file_name,
117 const std::string& contents);
123 static bool WriteFileAtomically(
const char* file_name,
124 const std::string& contents);
132 static bool Copy(
const char* from_file_name,
const char* to_file_name);
138 static int64_t CopyFile(
File* source,
File* destination);
145 static int64_t CopyFile(
File* source,
File* destination, int64_t max_copy);
149 static bool IsLocalRegularFile(
const char* file_name);
157 static std::string MakeCallbackFileName(
159 const std::string& name);
167 static bool ParseCallbackFileName(
168 const std::string& callback_file_name,
173 explicit File(
const std::string& file_name) : file_name_(file_name) {}
179 virtual bool Open() = 0;
186 static File* Create(
const char* file_name,
const char* mode);
188 static File* CreateInternalFile(
const char* file_name,
const char* mode);
191 std::string file_name_;
193 DISALLOW_COPY_AND_ASSIGN(
File);
198 #endif // PACKAGER_FILE_FILE_H_