diff options
author | thegeorg <thegeorg@yandex-team.com> | 2023-12-14 12:38:22 +0300 |
---|---|---|
committer | thegeorg <thegeorg@yandex-team.com> | 2023-12-14 13:41:33 +0300 |
commit | 2ec4b09046a0cdae37cc8591a3b80ff213e3440a (patch) | |
tree | b60ebe2924c12dbe33d89f897ad7370cb7777f69 /util | |
parent | 90fe6772091959f61dc45f60551feab9da2f8166 (diff) | |
download | ydb-2ec4b09046a0cdae37cc8591a3b80ff213e3440a.tar.gz |
Allow using std::filesystem::path when constructing TFileInput / TFileOutput
Diffstat (limited to 'util')
-rw-r--r-- | util/stream/file.cpp | 30 | ||||
-rw-r--r-- | util/stream/file.h | 10 |
2 files changed, 31 insertions, 9 deletions
diff --git a/util/stream/file.cpp b/util/stream/file.cpp index 0d3fbfc759..dcf89a48ab 100644 --- a/util/stream/file.cpp +++ b/util/stream/file.cpp @@ -3,12 +3,19 @@ #include <util/memory/blob.h> #include <util/generic/yexception.h> +TUnbufferedFileInput::TUnbufferedFileInput(const char* path) + : TUnbufferedFileInput(TFile(path, OPEN_MODE)) +{ +} + TUnbufferedFileInput::TUnbufferedFileInput(const TString& path) - : File_(path, OpenExisting | RdOnly | Seq) + : TUnbufferedFileInput(TFile(path, OPEN_MODE)) +{ +} + +TUnbufferedFileInput::TUnbufferedFileInput(const std::filesystem::path& path) + : TUnbufferedFileInput(TFile(path, OPEN_MODE)) { - if (!File_.IsOpen()) { - ythrow TIoException() << "file " << path << " not open"; - } } TUnbufferedFileInput::TUnbufferedFileInput(const TFile& file) @@ -42,12 +49,19 @@ size_t TUnbufferedFileInput::DoSkip(size_t len) { return newPos - oldPos; } +TUnbufferedFileOutput::TUnbufferedFileOutput(const char* path) + : TUnbufferedFileOutput(TFile(path, OPEN_MODE)) +{ +} + TUnbufferedFileOutput::TUnbufferedFileOutput(const TString& path) - : File_(path, CreateAlways | WrOnly | Seq) + : TUnbufferedFileOutput(TFile(path, OPEN_MODE)) +{ +} + +TUnbufferedFileOutput::TUnbufferedFileOutput(const std::filesystem::path& path) + : TUnbufferedFileOutput(TFile(path, OPEN_MODE)) { - if (!File_.IsOpen()) { - ythrow TFileError() << "can not open " << path; - } } TUnbufferedFileOutput::TUnbufferedFileOutput(const TFile& file) diff --git a/util/stream/file.h b/util/stream/file.h index c1cf4f591d..692a593d97 100644 --- a/util/stream/file.h +++ b/util/stream/file.h @@ -22,10 +22,14 @@ */ class TUnbufferedFileInput: public IInputStream { public: - TUnbufferedFileInput(const TFile& file); + TUnbufferedFileInput(const char* path); TUnbufferedFileInput(const TString& path); + TUnbufferedFileInput(const std::filesystem::path& path); + TUnbufferedFileInput(const TFile& file); private: + static constexpr EOpenMode OPEN_MODE = OpenExisting | RdOnly | Seq; + size_t DoRead(void* buf, size_t len) override; size_t DoSkip(size_t len) override; @@ -55,7 +59,9 @@ private: */ class TUnbufferedFileOutput: public IOutputStream { public: + TUnbufferedFileOutput(const char* path); TUnbufferedFileOutput(const TString& path); + TUnbufferedFileOutput(const std::filesystem::path& path); TUnbufferedFileOutput(const TFile& file); ~TUnbufferedFileOutput() override; @@ -63,6 +69,8 @@ public: TUnbufferedFileOutput& operator=(TUnbufferedFileOutput&&) noexcept = default; private: + static constexpr EOpenMode OPEN_MODE = CreateAlways | WrOnly | Seq; + void DoWrite(const void* buf, size_t len) override; void DoFlush() override; |