mirror of
https://github.com/shaka-project/shaka-packager.git
synced 2026-04-13 08:40:49 +00:00
This work was done over ~80 individual commits in the `cmake` branch, which are now being merged back into `main`. As a roll-up commit, it is too big to be reviewable, but each change was reviewed individually in context of the `cmake` branch. After this, the `cmake` branch will be renamed `cmake-porting-history` and preserved. --------- Co-authored-by: Geoff Jukes <geoffjukes@users.noreply.github.com> Co-authored-by: Bartek Zdanowski <bartek.zdanowski@gmail.com> Co-authored-by: Carlos Bentzen <cadubentzen@gmail.com> Co-authored-by: Dennis E. Mungai <2356871+Brainiarc7@users.noreply.github.com> Co-authored-by: Cosmin Stejerean <cstejerean@gmail.com> Co-authored-by: Carlos Bentzen <carlos.bentzen@bitmovin.com> Co-authored-by: Cosmin Stejerean <cstejerean@meta.com> Co-authored-by: Cosmin Stejerean <cosmin@offbytwo.com>
76 lines
1.8 KiB
C++
76 lines
1.8 KiB
C++
// Copyright 2017 Google LLC. All rights reserved.
|
|
//
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file or at
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
#include <packager/file/callback_file.h>
|
|
|
|
#include <absl/log/log.h>
|
|
|
|
#include <packager/macros/compiler.h>
|
|
#include <packager/macros/logging.h>
|
|
|
|
namespace shaka {
|
|
|
|
CallbackFile::CallbackFile(const char* file_name, const char* mode)
|
|
: File(file_name), file_mode_(mode) {}
|
|
|
|
CallbackFile::~CallbackFile() {}
|
|
|
|
bool CallbackFile::Close() {
|
|
delete this;
|
|
return true;
|
|
}
|
|
|
|
int64_t CallbackFile::Read(void* buffer, uint64_t length) {
|
|
if (!callback_params_->read_func) {
|
|
LOG(ERROR) << "Read function not defined.";
|
|
return -1;
|
|
}
|
|
return callback_params_->read_func(name_, buffer, length);
|
|
}
|
|
|
|
int64_t CallbackFile::Write(const void* buffer, uint64_t length) {
|
|
if (!callback_params_->write_func) {
|
|
LOG(ERROR) << "Write function not defined.";
|
|
return -1;
|
|
}
|
|
return callback_params_->write_func(name_, buffer, length);
|
|
}
|
|
|
|
void CallbackFile::CloseForWriting() {}
|
|
|
|
int64_t CallbackFile::Size() {
|
|
LOG(INFO) << "CallbackFile does not support Size().";
|
|
return -1;
|
|
}
|
|
|
|
bool CallbackFile::Flush() {
|
|
// Do nothing on Flush.
|
|
return true;
|
|
}
|
|
|
|
bool CallbackFile::Seek(uint64_t position) {
|
|
UNUSED(position);
|
|
VLOG(1) << "CallbackFile does not support Seek().";
|
|
return false;
|
|
}
|
|
|
|
bool CallbackFile::Tell(uint64_t* position) {
|
|
UNUSED(position);
|
|
VLOG(1) << "CallbackFile does not support Tell().";
|
|
return false;
|
|
}
|
|
|
|
bool CallbackFile::Open() {
|
|
if (file_mode_ != "r" && file_mode_ != "w" && file_mode_ != "rb" &&
|
|
file_mode_ != "wb") {
|
|
LOG(ERROR) << "CallbackFile does not support file mode " << file_mode_;
|
|
return false;
|
|
}
|
|
return ParseCallbackFileName(file_name(), &callback_params_, &name_);
|
|
}
|
|
|
|
} // namespace shaka
|