21constexpr int kDefaultBlockSize = 128 * 1024;
28 RDavixFileDes() : fd(nullptr), pos(&ctx) {}
29 RDavixFileDes(
const RDavixFileDes &) =
delete;
30 RDavixFileDes &
operator=(
const RDavixFileDes &) =
delete;
31 ~RDavixFileDes() =
default;
43 :
RRawFile(url, options), fFileDes(new RDavixFileDes())
49 if (fFileDes->fd !=
nullptr)
50 fFileDes->pos.close(fFileDes->fd,
nullptr);
55 return std::make_unique<RRawFileDavix>(fUrl, fOptions);
61 Davix::DavixError *err =
nullptr;
62 if (fFileDes->pos.stat(
nullptr, fUrl, &buf, &err) == -1) {
63 throw std::runtime_error(
"Cannot determine size of '" + fUrl +
"', error: " + err->getErrMsg());
70 Davix::DavixError *err =
nullptr;
71 fFileDes->fd = fFileDes->pos.open(
nullptr, fUrl, O_RDONLY, &err);
72 if (fFileDes->fd ==
nullptr) {
73 throw std::runtime_error(
"Cannot open '" + fUrl +
"', error: " + err->getErrMsg());
75 if (fOptions.fBlockSize < 0)
76 fOptions.fBlockSize = kDefaultBlockSize;
81 Davix::DavixError *err =
nullptr;
82 auto retval = fFileDes->pos.pread(fFileDes->fd, buffer, nbytes, offset, &err);
84 throw std::runtime_error(
"Cannot read from '" + fUrl +
"', error: " + err->getErrMsg());
86 return static_cast<size_t>(retval);
Binding & operator=(OUT(*fun)(void))
size_t ReadAtImpl(void *buffer, size_t nbytes, std::uint64_t offset) final
Derived classes should implement low-level reading without buffering.
std::unique_ptr< RRawFile > Clone() const final
Create a new RawFile that accesses the same resource. The file pointer is reset to zero.
RRawFileDavix(std::string_view url, RRawFile::ROptions options)
std::uint64_t GetSizeImpl() final
Derived classes should return the file size or kUnknownFileSize.
void OpenImpl() final
OpenImpl() is called at most once and before any call to either DoReadAt or DoGetSize.
The RRawFile provides read-only access to local and remote files.
basic_string_view< char > string_view
On construction, an ROptions parameter can customize the RRawFile behavior.