28#include <unordered_map>
63 const std::unordered_map<std::
string, std::
string> &config = {},
64 std::vector<std::unique_ptr<OperatorOption>> options = {});
91 std::
string Read(std::string_view path);
108 void Write(std::string_view path, std::string_view data);
117 void Write(std::string_view path, std::string_view data,
137 [[deprecated("Use
Exists() instead.")]]
161 void Copy(std::string_view src, std::string_view dst);
162 void Copy(std::string_view src, std::string_view dst,
171 void Rename(std::string_view src, std::string_view dst);
172 void Rename(std::string_view src, std::string_view dst,
208 void Destroy() noexcept;
228 std::streamsize
Read(
void *s, std::streamsize n);
230 std::streamsize
ReadAt(
void *s, std::streamsize n, uint64_t offset);
232 std::streampos
Seek(std::streamoff off, std::ios_base::seekdir way);
239 void Destroy() noexcept;
241 ffi::
Reader *reader_{
nullptr};
268 void Destroy() noexcept;
270 ffi::
Writer *writer_{
nullptr};
284 : reader_(std::move(reader)), buffer_start_pos_(0) {
285 setg(buffer_, buffer_, buffer_);
289 std::streamsize
xsgetn(
char *s, std::streamsize count)
override {
290 std::streamsize total_read = 0;
292 while (total_read < count) {
293 if (gptr() < egptr()) {
294 std::streamsize available_bytes = egptr() - gptr();
295 std::streamsize to_copy =
296 std::min(available_bytes, count - total_read);
297 std::memcpy(s + total_read, gptr(), to_copy);
299 total_read += to_copy;
303 if (
underflow() == traits_type::eof())
break;
310 if (gptr() < egptr()) {
311 return traits_type::to_int_type(*gptr());
315 buffer_start_pos_ +=
static_cast<std::streamoff
>(egptr() - eback());
317 std::streamsize n = reader_.
Read(buffer_,
sizeof(buffer_));
319 return traits_type::eof();
322 setg(buffer_, buffer_, buffer_ + n);
323 return traits_type::to_int_type(*gptr());
328 if (result != traits_type::eof()) {
334 std::streampos
seekoff(std::streamoff off, std::ios_base::seekdir dir,
335 std::ios_base::openmode which)
override {
336 if (dir == std::ios_base::cur && off == 0) {
338 return buffer_start_pos_ +
static_cast<std::streamoff
>(gptr() - eback());
342 std::streampos new_pos = reader_.
Seek(off, dir);
343 if (new_pos != std::streampos(-1)) {
344 buffer_start_pos_ = new_pos;
345 setg(buffer_, buffer_, buffer_);
351 std::ios_base::openmode which)
override {
352 return seekoff(pos, std::ios_base::beg, which);
358 std::streampos buffer_start_pos_;
362 : std::istream(&buf_), buf_(std::move(reader)) {}
365 ReaderStreamBuf buf_;
401 current_entry_ = lister_.Next();
407 if (current_entry_) {
408 current_entry_ = lister_.Next();
414 return current_entry_ != std::nullopt ||
415 other.current_entry_ != std::nullopt;
426 std::optional<Entry> current_entry_;
442 Lister(ffi::Lister *pointer)
noexcept;
444 void Destroy() noexcept;
446 ffi::
Lister *lister_{
nullptr};
Definition data_structure.hpp:340
The entry of a file or directory.
Definition data_structure.hpp:190
Definition opendal.hpp:392
std::ptrdiff_t difference_type
Definition opendal.hpp:396
Entry operator*()
Definition opendal.hpp:404
Iterator(Lister &lister)
Definition opendal.hpp:400
std::input_iterator_tag iterator_category
Definition opendal.hpp:394
Iterator(Lister &lister, bool) noexcept
Definition opendal.hpp:420
Iterator & operator++()
Definition opendal.hpp:406
bool operator!=(const Iterator &other) const
Definition opendal.hpp:413
Lister is designed to list the entries of a directory.
Definition opendal.hpp:380
std::optional< Entry > Next()
Get the next entry of the lister.
Lister(Lister &&other) noexcept
Iterator begin()
Definition opendal.hpp:436
Iterator end()
Definition opendal.hpp:437
Operator is the entry for all public APIs.
Definition opendal.hpp:51
void RemoveAll(const std::vector< std::string > &paths)
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.
Writer GetWriter(std::string_view path)
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:281
int_type uflow() override
Definition opendal.hpp:326
std::streampos seekoff(std::streamoff off, std::ios_base::seekdir dir, std::ios_base::openmode which) override
Definition opendal.hpp:334
std::streamsize xsgetn(char *s, std::streamsize count) override
Definition opendal.hpp:289
int_type underflow() override
Definition opendal.hpp:309
std::streampos seekpos(std::streampos pos, std::ios_base::openmode which) override
Definition opendal.hpp:350
ReaderStreamBuf(Reader &&reader)
Definition opendal.hpp:283
ReaderStream is a stream wrapper of Reader which provides iostream interface. It wraps the Reader to ...
Definition opendal.hpp:279
ReaderStream(Reader &&reader)
Definition opendal.hpp:361
Reader is designed to read data from the operator.
Definition opendal.hpp:222
Reader(Reader &&other) noexcept
std::streamsize ReadAt(void *s, std::streamsize n, uint64_t offset)
std::streamsize Read(void *s, std::streamsize n)
std::streampos Seek(std::streamoff off, std::ios_base::seekdir way)
Writer is designed to write a sequence of byte buffers to an object.
Definition opendal.hpp:251
void Write(std::string_view data)
Writer(Writer &&other) noexcept
Definition data_structure.hpp:29
Options for copy operations.
Definition data_structure.hpp:300
Options for delete operations.
Definition data_structure.hpp:321
Options for list and lister operations.
Definition data_structure.hpp:330
Options for read operations.
Definition data_structure.hpp:245
Options for creating readers.
Definition data_structure.hpp:265
Options for rename operations.
Definition data_structure.hpp:313
Options for stat operations.
Definition data_structure.hpp:230
Options for write and writer operations.
Definition data_structure.hpp:282