#pragma once #include "fwd.h" #include "input.h" #include "output.h" #include "buffered.h" #include "mem.h" #include #include /** * @addtogroup Streams_Files * @{ */ /** * Unbuffered file input stream. * * Note that the input is not buffered, which means that `ReadLine` calls will * be _very_ slow. */ class TUnbufferedFileInput: public IInputStream { public: TUnbufferedFileInput(const TFile& file); TUnbufferedFileInput(const TString& path); private: size_t DoRead(void* buf, size_t len) override; size_t DoSkip(size_t len) override; private: TFile File_; }; /** * Memory-mapped file input stream. */ class TMappedFileInput: public TMemoryInput { public: TMappedFileInput(const TFile& file); TMappedFileInput(const TString& path); ~TMappedFileInput() override; private: class TImpl; THolder Impl_; }; /** * File output stream. * * Note that the output is unbuffered, thus writing in many small chunks is * likely to be quite slow. */ class TUnbufferedFileOutput: public IOutputStream { public: TUnbufferedFileOutput(const TString& path); TUnbufferedFileOutput(const TFile& file); ~TUnbufferedFileOutput() override; TUnbufferedFileOutput(TUnbufferedFileOutput&&) noexcept = default; TUnbufferedFileOutput& operator=(TUnbufferedFileOutput&&) noexcept = default; private: void DoWrite(const void* buf, size_t len) override; void DoFlush() override; private: TFile File_; }; /** * Buffered file input stream. * * @see TBuffered */ class TFileInput: public TBuffered { public: template inline TFileInput(T&& t, size_t buf = 1 << 13) : TBuffered(buf, std::forward(t)) { } ~TFileInput() override = default; }; /** * Buffered file output stream. * * Currently deprecated, please use TFileOutput in new code. * * @deprecated * @see TBuffered */ class TFixedBufferFileOutput: public TBuffered { public: template inline TFixedBufferFileOutput(T&& t, size_t buf = 1 << 13) : TBuffered(buf, std::forward(t)) { } ~TFixedBufferFileOutput() override = default; }; /** @} */