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_;
bool Seek(uint64_t position) override
int64_t Write(const void *buffer, uint64_t length) override
const std::string & file_name() const
All the methods that are virtual are virtual for mocking.
bool Open() override
Internal open. Should not be used directly.
CallbackFile(const char *file_name, const char *mode)
std::function< int64_t(const std::string &name, void *buffer, uint64_t size)> read_func
std::function< int64_t(const std::string &name, const void *buffer, uint64_t size)> write_func
Define an abstract file interface.
int64_t Read(void *buffer, uint64_t length) override
static bool ParseCallbackFileName(const std::string &callback_file_name, const BufferCallbackParams **callback_params, std::string *name)
bool Tell(uint64_t *position) override