diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/stream/file.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/stream/file.cpp')
-rw-r--r-- | util/stream/file.cpp | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/util/stream/file.cpp b/util/stream/file.cpp index dc5d2f6311..da2ae8a2b3 100644 --- a/util/stream/file.cpp +++ b/util/stream/file.cpp @@ -1,30 +1,30 @@ -#include "file.h" - +#include "file.h" + #include <util/memory/blob.h> -#include <util/generic/yexception.h> - +#include <util/generic/yexception.h> + TUnbufferedFileInput::TUnbufferedFileInput(const TString& path) - : File_(path, OpenExisting | RdOnly | Seq) + : File_(path, OpenExisting | RdOnly | Seq) { - if (!File_.IsOpen()) { - ythrow TIoException() << "file " << path << " not open"; + if (!File_.IsOpen()) { + ythrow TIoException() << "file " << path << " not open"; } } TUnbufferedFileInput::TUnbufferedFileInput(const TFile& file) - : File_(file) -{ - if (!File_.IsOpen()) { - ythrow TIoException() << "file (" << file.GetName() << ") not open"; - } -} - + : File_(file) +{ + if (!File_.IsOpen()) { + ythrow TIoException() << "file (" << file.GetName() << ") not open"; + } +} + size_t TUnbufferedFileInput::DoRead(void* buf, size_t len) { return File_.ReadOrFail(buf, len); -} - +} + size_t TUnbufferedFileInput::DoSkip(size_t len) { - if (len < 384) { + if (len < 384) { /* Base implementation calls DoRead, which results in one system call * instead of three as in fair skip implementation. For small sizes * actually doing one read is cheaper. Experiments show that the @@ -32,66 +32,66 @@ size_t TUnbufferedFileInput::DoSkip(size_t len) { * in the range of 384-512 bytes (assuming that the file is in OS cache). */ return IInputStream::DoSkip(len); } - - /* TFile::Seek can seek beyond the end of file, so we need to do - * size check here. */ - i64 size = File_.GetLength(); - i64 oldPos = File_.GetPosition(); - i64 newPos = File_.Seek(Min<i64>(size, oldPos + len), sSet); - - return newPos - oldPos; + + /* TFile::Seek can seek beyond the end of file, so we need to do + * size check here. */ + i64 size = File_.GetLength(); + i64 oldPos = File_.GetPosition(); + i64 newPos = File_.Seek(Min<i64>(size, oldPos + len), sSet); + + return newPos - oldPos; } TUnbufferedFileOutput::TUnbufferedFileOutput(const TString& path) : File_(path, CreateAlways | WrOnly | Seq) -{ - if (!File_.IsOpen()) { - ythrow TFileError() << "can not open " << path; - } -} - +{ + if (!File_.IsOpen()) { + ythrow TFileError() << "can not open " << path; + } +} + TUnbufferedFileOutput::TUnbufferedFileOutput(const TFile& file) - : File_(file) -{ - if (!File_.IsOpen()) { - ythrow TIoException() << "closed file(" << file.GetName() << ") passed"; - } -} - + : File_(file) +{ + if (!File_.IsOpen()) { + ythrow TIoException() << "closed file(" << file.GetName() << ") passed"; + } +} + TUnbufferedFileOutput::~TUnbufferedFileOutput() = default; - + void TUnbufferedFileOutput::DoWrite(const void* buf, size_t len) { - File_.Write(buf, len); -} - + File_.Write(buf, len); +} + void TUnbufferedFileOutput::DoFlush() { - if (File_.IsOpen()) { - File_.Flush(); - } -} - -class TMappedFileInput::TImpl: public TBlob { -public: - inline TImpl(TFile file) - : TBlob(TBlob::FromFile(file)) - { + if (File_.IsOpen()) { + File_.Flush(); } - +} + +class TMappedFileInput::TImpl: public TBlob { +public: + inline TImpl(TFile file) + : TBlob(TBlob::FromFile(file)) + { + } + inline ~TImpl() = default; -}; - +}; + TMappedFileInput::TMappedFileInput(const TFile& file) : TMemoryInput(nullptr, 0) - , Impl_(new TImpl(file)) -{ - Reset(Impl_->Data(), Impl_->Size()); -} - + , Impl_(new TImpl(file)) +{ + Reset(Impl_->Data(), Impl_->Size()); +} + TMappedFileInput::TMappedFileInput(const TString& path) : TMemoryInput(nullptr, 0) - , Impl_(new TImpl(TFile(path, OpenExisting | RdOnly))) + , Impl_(new TImpl(TFile(path, OpenExisting | RdOnly))) { - Reset(Impl_->Data(), Impl_->Size()); + Reset(Impl_->Data(), Impl_->Size()); } TMappedFileInput::~TMappedFileInput() = default; |