26constexpr int kDefaultBlockSize = 4096;
30 :
RRawFile(url, options), fFilePtr(nullptr)
36 if (fFilePtr !=
nullptr)
42 return std::make_unique<RRawFileWin>(fUrl, fOptions);
48 long size = ftell(fFilePtr);
50 throw std::runtime_error(
"Cannot tell position counter in '" + fUrl +
51 "', error: " + std::string(strerror(errno)));
52 Seek(fFilePos, SEEK_SET);
58 fFilePtr = fopen(GetLocation(fUrl).c_str(),
"rb");
59 if (fFilePtr ==
nullptr)
60 throw std::runtime_error(
"Cannot open '" + fUrl +
"', error: " + std::string(strerror(errno)));
62 int res = setvbuf(fFilePtr,
nullptr, _IONBF, 0);
64 if (fOptions.fBlockSize < 0)
65 fOptions.fBlockSize = kDefaultBlockSize;
70 Seek(offset, SEEK_SET);
71 size_t res = fread(buffer, 1, nbytes, fFilePtr);
72 if ((res < nbytes) && (ferror(fFilePtr) != 0)) {
74 throw std::runtime_error(
"Cannot read from '" + fUrl +
"', error: " + std::string(strerror(errno)));
81 int res = fseek(fFilePtr, offset, whence);
83 throw std::runtime_error(
"Cannot seek in '" + fUrl +
"', error: " + std::string(strerror(errno)));
RRawFileWin(std::string_view url, RRawFile::ROptions options)
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.
std::uint64_t GetSizeImpl() final
Derived classes should return the file size or kUnknownFileSize.
void Seek(long offset, int whence)
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
static constexpr double L
On construction, an ROptions parameter can customize the RRawFile behavior.