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 extern const char* kHttpFilePrefix;
24 const int64_t kWholeFile = -1;
63 virtual int64_t
Read(
void* buffer, uint64_t length) = 0;
69 virtual int64_t
Write(
const void* buffer, uint64_t length) = 0;
73 virtual int64_t
Size() = 0;
85 virtual bool Seek(uint64_t position) = 0;
91 virtual bool Tell(uint64_t* position) = 0;
95 const std::string&
file_name()
const {
return file_name_; }
116 const std::string& contents);
123 const std::string& contents);
131 static bool Copy(
const char* from_file_name,
const char* to_file_name);
158 const std::string& name);
167 const std::string& callback_file_name,
185 static File* Create(
const char*
file_name,
const char* mode);
187 static File* CreateInternalFile(
const char*
file_name,
const char* mode);
190 std::string file_name_;
192 DISALLOW_COPY_AND_ASSIGN(
File);
Define an abstract file interface.
virtual bool Tell(uint64_t *position)=0
static File * OpenWithNoBuffering(const char *file_name, const char *mode)
static bool Delete(const char *file_name)
static bool WriteStringToFile(const char *file_name, const std::string &contents)
virtual bool Seek(uint64_t position)=0
const std::string & file_name() const
static bool WriteFileAtomically(const char *file_name, const std::string &contents)
virtual bool Open()=0
Internal open. Should not be used directly.
virtual int64_t Read(void *buffer, uint64_t length)=0
static std::string MakeCallbackFileName(const BufferCallbackParams &callback_params, const std::string &name)
static int64_t CopyFile(File *source, File *destination)
virtual int64_t Write(const void *buffer, uint64_t length)=0
static bool IsLocalRegularFile(const char *file_name)
static int64_t GetFileSize(const char *file_name)
static bool ReadFileToString(const char *file_name, std::string *contents)
static bool ParseCallbackFileName(const std::string &callback_file_name, const BufferCallbackParams **callback_params, std::string *name)
static bool Copy(const char *from_file_name, const char *to_file_name)
Declaration of class which implements a thread-safe circular buffer.
All the methods that are virtual are virtual for mocking.