27#include <unordered_map>
58 const std::unordered_map<std::
string, std::
string> &config = {});
85 std::
string Read(std::string_view path);
93 void Write(std::string_view path, std::string_view data);
109 [[deprecated("Use
Exists() instead.")]]
133 void Copy(std::string_view src, std::string_view dst);
141 void Rename(std::string_view src, std::string_view dst);
171 void Destroy() noexcept;
191 std::streamsize
Read(
void *s, std::streamsize n);
193 std::streampos
Seek(std::streamoff off, std::ios_base::seekdir way);
200 void Destroy() noexcept;
202 ffi::
Reader *reader_{
nullptr};
216 : reader_(std::move(reader)), buffer_start_pos_(0) {
217 setg(buffer_, buffer_, buffer_);
221 std::streamsize
xsgetn(
char *s, std::streamsize count)
override {
222 std::streamsize total_read = 0;
224 while (total_read < count) {
225 if (gptr() < egptr()) {
226 std::streamsize available_bytes = egptr() - gptr();
227 std::streamsize to_copy =
228 std::min(available_bytes, count - total_read);
229 std::memcpy(s + total_read, gptr(), to_copy);
231 total_read += to_copy;
235 if (
underflow() == traits_type::eof())
break;
242 if (gptr() < egptr()) {
243 return traits_type::to_int_type(*gptr());
247 buffer_start_pos_ += (egptr() - eback());
249 std::streamsize n = reader_.
Read(buffer_,
sizeof(buffer_));
251 return traits_type::eof();
254 setg(buffer_, buffer_, buffer_ + n);
255 return traits_type::to_int_type(*gptr());
260 if (result != traits_type::eof()) {
266 std::streampos
seekoff(std::streamoff off, std::ios_base::seekdir dir,
267 std::ios_base::openmode which)
override {
268 if (dir == std::ios_base::cur && off == 0) {
270 return buffer_start_pos_ + (gptr() - eback());
274 std::streampos new_pos = reader_.
Seek(off, dir);
275 if (new_pos != std::streampos(-1)) {
276 buffer_start_pos_ = new_pos;
277 setg(buffer_, buffer_, buffer_);
283 std::ios_base::openmode which)
override {
284 return seekoff(pos, std::ios_base::beg, which);
290 std::streampos buffer_start_pos_;
294 : std::istream(&buf_), buf_(std::move(reader)) {}
297 ReaderStreamBuf buf_;
333 current_entry_ = lister_.Next();
339 if (current_entry_) {
340 current_entry_ = lister_.Next();
346 return current_entry_ != std::nullopt ||
347 other.current_entry_ != std::nullopt;
358 std::optional<Entry> current_entry_;
374 Lister(ffi::Lister *pointer)
noexcept;
376 void Destroy() noexcept;
378 ffi::
Lister *lister_{
nullptr};
Definition data_structure.hpp:195
The entry of a file or directory.
Definition data_structure.hpp:188
Definition opendal.hpp:324
std::ptrdiff_t difference_type
Definition opendal.hpp:328
Entry operator*()
Definition opendal.hpp:336
Iterator(Lister &lister)
Definition opendal.hpp:332
std::input_iterator_tag iterator_category
Definition opendal.hpp:326
Iterator(Lister &lister, bool) noexcept
Definition opendal.hpp:352
Iterator & operator++()
Definition opendal.hpp:338
bool operator!=(const Iterator &other) const
Definition opendal.hpp:345
Lister is designed to list the entries of a directory.
Definition opendal.hpp:312
std::optional< Entry > Next()
Get the next entry of the lister.
Lister(Lister &&other) noexcept
Iterator begin()
Definition opendal.hpp:368
Iterator end()
Definition opendal.hpp:369
Operator is the entry for all public APIs.
Definition opendal.hpp:47
void Remove(std::string_view path)
Remove a file or directory.
Reader GetReader(std::string_view path)
Read data from the operator.
void Rename(std::string_view src, std::string_view dst)
Rename a file from src to dst.
Operator(Operator &&other) noexcept
bool Exists(std::string_view path)
Check if the path exists.
bool Available() const
Check if the operator is available.
std::string Read(std::string_view path)
Read data from the operator.
Operator(const Operator &)=delete
bool IsExist(std::string_view path)
Check if the path exists.
Operator & operator=(const Operator &)=delete
Lister GetLister(std::string_view path)
void CreateDir(std::string_view path)
Create a directory.
Operator & operator=(Operator &&other) noexcept
void Copy(std::string_view src, std::string_view dst)
Copy a file from src to dst.
void Write(std::string_view path, std::string_view data)
Write data to the operator.
std::vector< Entry > List(std::string_view path)
List the entries of a directory.
Metadata Stat(std::string_view path)
Get the metadata of a file or directory.
Definition opendal.hpp:213
int_type uflow() override
Definition opendal.hpp:258
std::streampos seekoff(std::streamoff off, std::ios_base::seekdir dir, std::ios_base::openmode which) override
Definition opendal.hpp:266
std::streamsize xsgetn(char *s, std::streamsize count) override
Definition opendal.hpp:221
int_type underflow() override
Definition opendal.hpp:241
std::streampos seekpos(std::streampos pos, std::ios_base::openmode which) override
Definition opendal.hpp:282
ReaderStreamBuf(Reader &&reader)
Definition opendal.hpp:215
ReaderStream is a stream wrapper of Reader which provides iostream interface. It wraps the Reader to ...
Definition opendal.hpp:211
ReaderStream(Reader &&reader)
Definition opendal.hpp:293
Reader is designed to read data from the operator.
Definition opendal.hpp:185
Reader(Reader &&other) noexcept
std::streamsize Read(void *s, std::streamsize n)
std::streampos Seek(std::streamoff off, std::ios_base::seekdir way)
Definition data_structure.hpp:27