7 #include "packager/file/callback_file.h" 9 #include "packager/base/logging.h" 14 :
File(file_name), file_mode_(mode) {}
16 CallbackFile::~CallbackFile() {}
25 LOG(ERROR) <<
"Read function not defined.";
28 return callback_params_->
read_func(name_, buffer, length);
33 LOG(ERROR) <<
"Write function not defined.";
36 return callback_params_->
write_func(name_, buffer, length);
40 LOG(INFO) <<
"CallbackFile does not support Size().";
50 VLOG(1) <<
"CallbackFile does not support Seek().";
55 VLOG(1) <<
"CallbackFile does not support Tell().";
60 if (file_mode_ !=
"r" && file_mode_ !=
"w" && file_mode_ !=
"rb" &&
62 LOG(ERROR) <<
"CallbackFile does not support file mode " << file_mode_;
std::function< int64_t(const std::string &name, void *buffer, uint64_t size)> read_func
Define an abstract file interface.
const std::string & file_name() const
int64_t Write(const void *buffer, uint64_t length) override
All the methods that are virtual are virtual for mocking.
bool Tell(uint64_t *position) override
bool Seek(uint64_t position) override
std::function< int64_t(const std::string &name, const void *buffer, uint64_t size)> write_func
static bool ParseCallbackFileName(const std::string &callback_file_name, const BufferCallbackParams **callback_params, std::string *name)
bool Open() override
Internal open. Should not be used directly.
int64_t Read(void *buffer, uint64_t length) override
CallbackFile(const char *file_name, const char *mode)