| 136 | bool closed() const { return !is_open_; } |
| 137 | |
| 138 | Result<int64_t> ReadAt(int64_t position, int64_t nbytes, uint8_t* buffer) { |
| 139 | RETURN_NOT_OK(CheckClosed()); |
| 140 | if (!driver_->HasPread()) { |
| 141 | std::lock_guard<std::mutex> guard(lock_); |
| 142 | RETURN_NOT_OK(Seek(position)); |
| 143 | return Read(nbytes, buffer); |
| 144 | } |
| 145 | |
| 146 | constexpr int64_t kMaxBlockSize = std::numeric_limits<int32_t>::max(); |
| 147 | int64_t total_bytes = 0; |
| 148 | while (nbytes > 0) { |
| 149 | const auto block_size = static_cast<tSize>(std::min(kMaxBlockSize, nbytes)); |
| 150 | tSize ret = |
| 151 | driver_->Pread(fs_, file_, static_cast<tOffset>(position), buffer, block_size); |
| 152 | CHECK_FAILURE(ret, "read"); |
| 153 | DCHECK_LE(ret, block_size); |
| 154 | if (ret == 0) { |
| 155 | break; // EOF |
| 156 | } |
| 157 | buffer += ret; |
| 158 | total_bytes += ret; |
| 159 | position += ret; |
| 160 | nbytes -= ret; |
| 161 | } |
| 162 | return total_bytes; |
| 163 | } |
| 164 | |
| 165 | Result<std::shared_ptr<Buffer>> ReadAt(int64_t position, int64_t nbytes) { |
| 166 | RETURN_NOT_OK(CheckClosed()); |
nothing calls this directly
no test coverage detected